1

I would like to access the PDFium API, that is the pdf viewer in Chrome.

It is not clear what can I do.

Some old questions give some hints.

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

Call pdfium (chrome native pdf viewer) from javascript

I created a HTML file but I see that the methods of the plugin are not working.

<html>
<body >
<embed id='embedId' width='100%' height='100%' name='plugin' src='C:\path\file.pdf' type='application/pdf' />
<input type="button" value="Click me" onclick="embedEl=getElementById('embedId'); embedEl.selectAll();">
</body>
 </html>

I would like to know whether the API is available at present time in Chrome (so to be able to build something upon it) or not.

P5music
  • 3,197
  • 2
  • 32
  • 81

1 Answers1

-1

Hi you can find some API methods here: https://cs.chromium.org/chromium/src/chrome/browser/resources/pdf/pdf_scripting_api.js

Here is a basic example, it gives out an alert when the PDF loads.

<html>
<body style="overflow:hidden;">
<embed width="100%" height="100%" id="plugin" src="test.pdf" />


    <script type="text/javascript" src="pdf_scripting_api.js" />
var plugin = document.getElementById("plugin");
var scriptingAPI = new PDFScriptingAPI(window, plugin);

scriptingAPI.setLoadCallback(function(success)
{
    alert(success);
});        


    </script> 


</body>

JJ McKool
  • 45
  • 4
  • 1
    Thanks, but I see no notification when the pdf file is loaded. I put the HTML file, pdf file and library in the same folder, then "open with Chrome" from the File Manager. What's wrong? – P5music Oct 05 '19 at 08:59