PDF-Writer
PDF-Writer copied to clipboard
Adding 'print' javascript to an existing PDF file
Hi Gal, Very nice project, thanks!
Can you please guide me what's the best and easiest way to make an existing PDF file to be 'auto-printed' when it's downloaded to a browser?
Thanks a lot!
Amit
You should not auto print onto paper. It's their paper, not yours. Let the person downloading decide whether to print or to read it in a pdf reader.
On Tue, Jul 26, 2016, 10:45 amitkanfer [email protected] wrote:
Hi Gal, Very nice project, thanks!
Can you please guide me what's the best and easiest way to make an existing PDF file to be 'auto-printed' when it's downloaded to a browser?
Thanks a lot!
Amit
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/galkahana/PDF-Writer/issues/55, or mute the thread https://github.com/notifications/unsubscribe-auth/AACslhEzudnjvScFC1CemX0cRXSymkwEks5qZjmogaJpZM4JVWjw .
:) Seriously, Let me rephrase - automatically open the print dialog.
Nice one.
Did some looking around and it turns out that you can actually run javascript code as the document opens. and running something like this.print loads the dialog. at least when opened in acrobat...you can try other envs.
the key things to do are:
- Create Javascript Action object with "this.print()" as its command
- Attach this action object to the document root (a.k.a catalog) as its "OpenAction". This is done by creating modified version of the document root with this "OpenAction" key added.
It's just as possible to do so also with new documents, and not modified ones. In that case step 1 remains the same. Step 2 is changed to simply adding the key while hummus writes the document root by listeting to the OnCatalogWrite
event like this:
pdfWriter.getEvents().on('OnCatalogWrite',function(params) {
params.catalogDictionaryContext
.writeKey('OpenAction')
.writeObjectReferenceValue(actionObjectID);
});