开发者

Javascript: Simulate PDF Print

I have an embedded PDF in my HTML.

<object id="myPDF" typ开发者_StackOverflowe="application/pdf" data="visual.pdf" style="width:500px; height:500px"></object>

This works perfectly, and the file is displayed on the page, along with the basic features such as "print", "save", etc.

Is there any way of providing <input type="button" /> whose onclick function will invoke the "print" functionality of the embedded PDF? The reason for this is because I want to hide the tag, and just provide a link or a button which will print the hidden document.


put an iframe in html page.

include your pdf inside iframe.

Then which ever button click you want to show PDFs

onclick='window.open ("yourpdf.html","mywindow");'

after loading this page call window.print();


I would imagine that you could call some functions on the PDF reader with Javascript. However, please don't do this. Not everyone uses Adobe's Acrobat Reader to read PDFs. Other readers won't support your code. Because of this, it isn't possible.

Furthermore, it isn't advisable to use the <object> tag. It is best to leave it up to the user, and give a simple link to the PDF. Then it will work for anyone with a compatible reader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜