2

I'm linking to a PDF, but instead of it simply downloading or opening within browser, I'd like it to open with the print window open - ready for the user to print.

How do I go about that please? Or is it all based on your browser settings so impossible to force?

Thanks

Cazmaraline
  • 235
  • 1
  • 10
  • Duplicate of this question (which has good answers, too): http://stackoverflow.com/questions/687675/can-a-pdf-files-print-dialog-be-opened-with-javascript/2495430 – pixelistik Jun 29 '12 at 14:10

2 Answers2

2

One solution (short version):

  1. Open an iframe with the pdf in it, setting the width and height to 0 so that it is not shown

  2. Inject some javascript into the PDF-file

  3. When the javascript is run because the PDF is displayed, the print dialoge from adobe will be displayed.

Long version and implementation code is available from this codeproject.com-post

Sindre
  • 3,880
  • 2
  • 26
  • 39
1

As a refinement to the method referenced Sindre, I found that you can simply set the openAction of the document to be the pre-defined PRINTDIALOG action. Using iText (in Java), it's simply:

writer.SetOpenAction( new PdfAction( PdfAction.PRINTDIALOG ));

This avoids using JavaScript, which could be disabled as a security measure.

kero
  • 10,647
  • 5
  • 41
  • 51
Ben Schreiber
  • 377
  • 2
  • 13