Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

google chrome - does pdfium expose its api to javascript? i want to get the number of current page, but how to do this?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...