views:

5379

answers:

4

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?

+3  A: 

Probably not because the print command is being sent directly from the PDF application and not the browser(which the JS interacts with).

Paperino
A: 

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.

Did you test this code? I get an error that says "Object doesn't support this property of method".
ichiban
+2  A: 

Yes you can...

PDF 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

Edward
A: 

embed:

< object type="application/pdf" data="example.pdf" width="100%" height="100%" id="examplePDF" name="examplePDF" >< param name='src' value='example.pdf'/>< /object>

< script> examplePDF.printWithDialog(); < /script>

May have to fool around with the ids/names. Using adobe reader...

RandomGuy87