Print Page | Close Window

Javascript to auto-print on open

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1697
Printed Date: 04 May 24 at 9:52AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Javascript to auto-print on open
Posted By: Eric24
Subject: Javascript to auto-print on open
Date Posted: 03 Jan 11 at 5:04AM
I'm having trouble finding the appropriate Javascript to add to the document (via SetOpenActionJavaScript, presumably) to get Acrobat Reader (etc.) to automatically print the document when it's opened. Of course, I realize that it won't actually print the document "silently", but it seems like it should be possible to get it to launch the user's print dialog.



Replies:
Posted By: Ingo
Date Posted: 03 Jan 11 at 8:56AM
Hi Eric!

Using the Adobe Reader you can deal a bit with the following two lines.
c = Reader with path / Edit1.Text = pdf-document with path:
//  ShellExecute(hinstance,'open',PChar(c),PChar('/p ' + Edit1.Text),nil,SW_SHOWNORMAL);
//  ShellExecute(hinstance,'open',PChar(Edit1.Text),PChar('/p /h '),nil,SW_SHOWNORMAL);

You can try using keyboard-events, too:
//    Keybd_Event(VK_MENU,0,0,0);
//    Keybd_Event(VK_F4,0,0,0);
//    Keybd_Event(VK_F4,0,KEYEVENTF_KEYUP,0);
//    Keybd_Event(VK_MENU,0,KEYEVENTF_KEYUP,0);

Or try this one:
    ShellExecute(hinstance,'open',PChar(Edit1.Text),nil,nil,SW_SHOWNORMAL);
    sleep(2000);
   
    Keybd_Event(VK_CONTROL,0,0,0);
    Keybd_Event(Ord('P'),MapVirtualKey(Ord('P'), 0),0,0);
    Keybd_Event(Ord('P'),MapVirtualKey(Ord('P'), 0),KEYEVENTF_KEYUP,0);
    Keybd_Event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);

Cheers, Ingo




Posted By: Eric24
Date Posted: 03 Jan 11 at 3:51PM
Ingo--
Yes, those methods I'm familiar with, but I need to do this with JavaScript, as I don't have control of actually launching the reader. I am generating a PDF file on the server that is delivered to the reader within a browser frame--that works fine, I just want to automatically start the print process (i.e. show the print dialog) as soon as the document has been loaded by the reader-in-browser. That seems possible, in that there is a document JavaScript function to print and a way to add JavaScript to the "onOpen" event, but it's not working for me.
--Eric


Posted By: Rowan
Date Posted: 03 Jan 11 at 3:54PM
Which version of Adobe Reader are you using?


Posted By: Eric24
Date Posted: 03 Jan 11 at 10:46PM
Who knows? :) Whatever the end-user has installed. We are testing with 8, 9, and X.
--Eric


Posted By: Ingo
Date Posted: 04 Jan 11 at 7:34AM
Hi Eric!

...and perhaps it's Foxit.
You want a common javascript solution to insert into the pdf for calling the printer dialog.
The prob is that each printer dialog from the external pdf-control has slightly different parameters/properties. So you won't get a solution covering all things.
QuickPDF has a simple functionality for printing pdf-documents.
Perhaps that's the best for you now?

Cheers, Ingo
 


Posted By: Dimitry
Date Posted: 15 Jan 11 at 11:13AM
There is function in Quick PDF Library called SetOpenActionJavaScript().
It embedds a block of JavaScript that is executed as the document is opened.
So it takes just to load PDF file, add some JavaScript and save modyfied PDF.
 
The most simple JavaScript that prints entire document looks like:
  this.print()
 
In addition here is useful article about http://www.planetpdf.com/developer/article.asp?ContentID=printing_page_ranges_quickly_w - Printing page ranges quickly with JavaScript
 


-------------
Regards,
Dmitry


Posted By: Ruturaaj
Date Posted: 15 Jan 11 at 6:43PM
Success of all these methods depends on the Reader Preferences and Security settings, be aware of that please.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk