Can a PDF file's print dialog be opened with Javascript?

Viewed 147391

I know how to open a webpage in a new window and add javascript so the print dialog pops up. Is there a way to do a similar thing with a PDF file?

10 Answers

Yes you can...

PDFs have Javascript support. I needed to have auto print capabilities when a PHP-generated PDF was created and I was able to use FPDF to get it to work:

http://www.fpdf.org/en/script/script36.php

Another solution:

<input type="button" value="Print" onclick="document.getElementById('PDFtoPrint').focus(); document.getElementById('PDFtoPrint').contentWindow.print();">

if you embed the pdf in your webpage and reference the object id, you should be able to do it.

eg. in your HTML:

<object ID="examplePDF" type="application/pdf" data="example.pdf" width="500" height="500">

in your javascript:

<script>

var pdf = document.getElementById("examplePDF");

pdf.print();

</script>

I hope that helps.

Related