Accessing PDFium plugin methods with JS in Chrome 2019

*爱你&永不变心* 提交于 2021-02-18 19:35:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!