php - how to open print window while a pdf file is opened in web page?

自古美人都是妖i 提交于 2019-12-11 08:09:28

问题


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?


回答1:


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.




回答2:


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();"/>



来源:https://stackoverflow.com/questions/1210423/php-how-to-open-print-window-while-a-pdf-file-is-opened-in-web-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!