pdfium是否将其api暴露给javascript?我想获取当前页面的数量,但是如何做到这一点? [英] does pdfium expose its api to javascript? i want to get the number of current page, but how to do this?

查看:280
本文介绍了pdfium是否将其api暴露给javascript?我想获取当前页面的数量,但是如何做到这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道pdfium现在是Chrome的一部分,这是一个很好的PDF渲染,但我遇到了一些问题。



代码如下,默认页面是12页,由#页= 12分配,当这个页面打开时,我可以跳转或导航到其他页面,但如何使用JavaScript获取页码?

 < head>是否有任何js api可以用来获取页码? 
< style type =text / css>
.pdf {
width:100%;
身高:99%;
}
< / style>
< / head>

< div>
okok
< / div>

< iframe class =pdfsrc =http://127.0.0.1/test.pdf#page=12frameborder =0>< / iframe>


解决方案

我也在找JS API。

http:// src。 chromium.org/viewvc/chrome/trunk/src/pdf/instance.cc



如果有人需要它,有以下方法:

  object accessibility()
bool documentLoadComplete()
数字getHeight()$ b $数字getHorizo​​ntalScrollbarThickness()
字符串getPageLocationNormalized()
数字getVerticalScrollbarThickness()$ b $数字getWidth()
double getZoomLevel()
void goToPage(int arg)
void grayscale(bool arg)
void loadPreviewPage(string arg0,int arg1)
void onload(function arg)
void onPluginSizeChanged(function arg)
void onScroll(function arg)
pageXOffset )
page pageOffset()
void printPreviewPageCount(int arg)
void reload()
void removePrintButton()
void resetPrintPreviewUrl(string arg)
void sendKeyEvent(number arg)
void se tPageNumbers(string arg)
void setPageXOffset(number arg)
void setPageYOffset(number arg)
void setZoomLevel(double arg)$ b $ void fitToHeight()
void fitToWidth )
void zoomIn()
void zoomOut()
void print()

获取当前页面的示例如下所示:

 < html> 
< head>
< script type ='text / javascript'>

window.addEventListener('load',function(){

var embed = document.getElementsByName('plugin')[0];
// this方法应该返回页面的位置(不是页码,我想对在嵌入窗口中显示的PDF部分进行一些计算)
alert(embed.getPageLocationNormalized());
//我们可以使用其他API方法
embed.removePrintButton();

},false);
< / script>
< / head>
< body marginwidth ='0'marginheight ='0'style ='background-color:rgb(38,38,38)'width ='100%'height ='100%'>
< embed width ='100%'height ='100%'name ='plugin'src ='path_to_pdf_file'type ='application / pdf'/>
< / body>
< / html>


as we all know pdfium is now part of chrome, and this is a nice pdf render, but i am confronted with some problem.

the code is as follows, the default page is 12 as sepcified by the #page=12 assignment, when this page is opened, i could jump or navigate to other pages, but how to get the page number using javascript? is there any js api i can use to the get the page number?

<head>
<style type="text/css">
  .pdf {
    width: 100%;
    height: 99%;
  }
</style>
</head>

<div>
  okok
</div>

<iframe class="pdf" src="http://127.0.0.1/test.pdf#page=12" frameborder="0"></iframe>

解决方案

I was finding the JS API too. On http://src.chromium.org/viewvc/chrome/trunk/src/pdf/instance.cc

there are the following methods if someone need it:

object accessibility()
bool   documentLoadComplete()
number getHeight()
number getHorizontalScrollbarThickness()
string getPageLocationNormalized()
number getVerticalScrollbarThickness()
number getWidth()
double getZoomLevel()
void   goToPage(int arg)
void   grayscale(bool arg)
void   loadPreviewPage(string arg0, int arg1)
void   onload(function arg)
void   onPluginSizeChanged(function arg)
void   onScroll(function arg)
number pageXOffset()
number pageYOffset()
void   printPreviewPageCount(int arg)
void   reload()
void   removePrintButton()
void   resetPrintPreviewUrl(string arg)
void   sendKeyEvent(number arg)
void   setPageNumbers(string arg)
void   setPageXOffset(number arg)
void   setPageYOffset(number arg)
void   setZoomLevel(double arg)
void   fitToHeight()
void   fitToWidth()
void   zoomIn()
void   zoomOut()
void   print()

an example to get the current page is like that

<html>
    <head>
        <script type='text/javascript'>

            window.addEventListener('load', function(){

                var embed = document.getElementsByName('plugin')[0];
                // this method should return the page location (not the page number, i suppose that made some calculation on the portion of PDF that is showed in the embed window)
                alert(embed.getPageLocationNormalized());
                // we can use other api methods
                embed.removePrintButton();

            }, false);
        </script>
    </head>
    <body marginwidth='0' marginheight='0' style='background-color: rgb(38,38,38)' width='100%' height='100%'>
        <embed width='100%' height='100%' name='plugin' src='path_to_pdf_file' type='application/pdf' />
    </body>
</html>

这篇关于pdfium是否将其api暴露给javascript?我想获取当前页面的数量,但是如何做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆