[reportlab-users] Embedding JavaScript in PDF and a bug report

Andrew Cutler andrew at adlibre.com.au
Thu Apr 5 01:56:35 EDT 2012


Quite a few people have asked how to embed JavaScript in ReportLab
generated PDF's (links #1 #2 #3 below) and I thought I'd post this
here for the benefit of others.

The solution is quite simple, so it seems. To force a PDF to
automatically print, embed the following JavaScript:

from reportlab.pdfbase import pdfdoc
pdfdoc.PDFCatalog.OpenAction =
'<</S/JavaScript/JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)>>'

Now the bug report:

ReportLab 2.5 Has a typo. "OpenActions" should be "OpenAction" as per
ISO 32000-1:2008.

diff -r tmp/lib/python2.7/site-packages/reportlab/pdfbase/pdfdoc.py
lib/python2.7/site-packages/reportlab/pdfbase/pdfdoc.py
1022c1022
< Dests Outlines Pages Threads AcroForm Names OpenAction PageMode URI
---

> Dests Outlines Pages Threads AcroForm Names OpenActions PageMode URI


I've also covered this on my blog. Link #4

[#1] http://two.pairlist.net/pipermail/reportlab-users/2008-September/007313.html
[#2] http://two.pairlist.net/pipermail/reportlab-users/2008-October/007539.html
[#3] http://two.pairlist.net/pipermail/reportlab-users/2010-February/009309.html
[#4] http://blog.adlibre.org/2012/04/05/automatically-print-pdf-generated-reportlab/

Cheers,
--
Andrew Cutler


More information about the reportlab-users mailing list