1

I have a HTML page that has a link to a PDF. This PDF opens in a new window. The parent HTML page has a File->Print menu item. When the user clicks Print I want to be able to automatically open the PDF and print it. The printing part is where I am stuck.

Any help would be much appreciated.

Thanks.

Daveo
  • 19,018
  • 10
  • 48
  • 71
  • possible duplicate of [Silent print a embedded PDF](http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf) and [many others](http://stackoverflow.com/search?q=\[javascript\]+print+pdf) – Matt Ball Jan 25 '11 at 04:00

2 Answers2

5

If you open that window with a specific name (e.g. target="nameofwin") in the link pointing at the PDF, you might get away with nameofwin.print(). However, I'm not sure if that'd work since the PDF will be shown using a plugin, and not be a native part of the page. There may be some API that allows you to interface with the PDF display plugin, but then you're stuck wondering if you've got Acrobat or FoxIt or WhateverElse running in there.

Marc B
  • 356,200
  • 43
  • 426
  • 500
0

You can probably use PDF.js to render the PDF in a hidden div. Then, on your "print" button, register a click in which you add a new print stylesheet to the document, show that div, print the window and then remove the print stylesheet.

weisjohn
  • 793
  • 5
  • 9