Does pdfium disclose its javascript api? I want to get the current page number, but how to do it?

as we all know, pdfium is now part of chrome and this is a good PDF rendering, but I ran into some kind of problem.

the code is as follows, by default, the default page is 12, assigned by assignment # page = 12, when this page is open, I can skip or move to other pages, but how to get the page number using javascript? is there any js api that i can use to 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>
+3
source share
1 answer

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

, - :

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()

, ,

<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>
+1

Source: https://habr.com/ru/post/1619997/


All Articles