tags:

views:

533

answers:

2

I use FPDF to generate a pdf file and open it in a new window.

how to pop up the print window when it is opened in a new window?

A: 

Put the following into your <body> tag in the popup window:

<body onload="window.print()" />

This is Javascript, which will then open the browser's Print dialog. You cannot print directly from Javascript, but you can open the prompt.

If you're just opening the raw PDF in the window, you could control it from the parent window as well, either in a button, or any other javascript handler:

<input type="button" value="Generate PDF" onclick="var w = window.open('generated_pdf.pdf','mywin'); w.print();"/>

zombat
+1  A: 

Zombat's answer works if you're dealing with a web page, but a PDF file has no body tag. With a PDF file I'm not sure it's possible.

BUT! I would argue that it's better this way anyway. Making the user hit ctrl-p to print is less invasive than assuming they want to print and "helpfully" throwing up the dialog for them. IMO of course.

Ryan Ballantyne