问题
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.
回答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>
来源:https://stackoverflow.com/questions/57326644/accessing-pdfium-plugin-methods-with-js-in-chrome-2019