simcoweb Posted February 22, 2011 Share Posted February 22, 2011 We are using a PDF generator plugin for Wordpress that creates the PDF for the page being viewed. We'd also like to add the option for the visitor to generate AND print the PDF (option #1 just to generate and download, option #2 to generate and print). However, when they choose the 'print' option we want the PDF file to generate, open in a new tab/window, and immediately display the printer dialog box so all they have to do is hit the Print button. I've seen this done before and, from what i've found on how to do it, it requires embedding the javascript code into the PDF file which then, when being opened by the browser, acts on the command to open the printer dialog box. Anyone have a solution for this? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/228449-need-javascript-to-open-print-dialog-box-in-pdf/ Share on other sites More sharing options...
sunfighter Posted February 26, 2011 Share Posted February 26, 2011 This page should show you how it's done. http://www.fpdf.org/en/script/script36.php Quote Link to comment https://forums.phpfreaks.com/topic/228449-need-javascript-to-open-print-dialog-box-in-pdf/#findComment-1179902 Share on other sites More sharing options...
simcoweb Posted February 26, 2011 Author Share Posted February 26, 2011 Thanks for your post. I had already found that link through another source. The problem is it's using a completely different library/class to generate the PDF files ( the fpdf.php ). I emailed the that author but did not hear back. I was hoping he would explain what part of the code was necessary element in opening the print dialog box and how it could be adapted to our use. The first code box shows that it 'requires' the fpdf.php file to work and states it's an extension of that file. Then the next code box shows an example of how to do exactly what we want, open the dialog box, but there's nothing about how this code actually gets INTO the PDF file. What I really need, regarding that script, is how it can be used with other scripts other than the fpdf.php. As mentioned, we're already using a Wordpress plugin that generates the PDF files just fine. All we want is to have it open with the print dialog box. Do you have any ideas on how the code from that link would be adapted into our use? Quote Link to comment https://forums.phpfreaks.com/topic/228449-need-javascript-to-open-print-dialog-box-in-pdf/#findComment-1180053 Share on other sites More sharing options...
nogray Posted February 26, 2011 Share Posted February 26, 2011 You should review the Acrobat JavaScript Scripting Reference at http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/javascript/AcroJS.pdf In Page 507, you'll find the following example, // get the printParams object of the default printer var pp = this.getPrintParams(); // set some properties pp.interactive = pp.constants.interactionLevel.automatic; pp.colorOverride = pp.colorOverrides.mono; // print this.print(pp); You would need to review the document for details though. Quote Link to comment https://forums.phpfreaks.com/topic/228449-need-javascript-to-open-print-dialog-box-in-pdf/#findComment-1180073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.