[reportlab-users] PDF encryption

J. R. Carroll jrcarroll at jrcresearch.net
Mon Mar 25 17:01:08 EDT 2013


Hi Dinu,

This worked just fine for me... I think what you want is "ownerPassword"
not "userPassword". This gives permissions to view, but I am unable to
PRINT or COPY. The first parameter you are passing (non keyword), is for
userPassword. I just set it to an empty string and it seems to work just
fine.

Also PLEASE BE AWARE... I develop in Linux and test in Windows (cross-test
in most cases). I first tested this in Linux and it did not work...
suspecting that it was up to the rendering program to honor this (and not
the fault of reportlab/Postscript), I then moved it over to Windows and
opened it up with Adobe Reader and it worked like a charm. I've never used
this feature before, so if someone sees a violation of some kind, mea
culpa.


from reportlab.lib import pdfencrypt
from reportlab.pdfgen import canvas

enc = pdfencrypt.StandardEncryption("", ownerPassword="secret", canPrint=0,
canCopy=0)
c = canvas.Canvas("hello-enc.pdf", encrypt=enc)
c.drawString(100, 100, "Hello World")
c.showPage()
c.save()


You might want to (re)read the section on "Encryption" from
<http://www.reportlab.com/docs/reportlab-userguide.pdf>
here <http://www.reportlab.com/docs/reportlab-userguide.pdf> (your example
is near identical, so I suspect you were already referencing this, but just
making sure you got all the tools you need!).

Let me know if you need more help (or if I missed the mark),

-J

----


J. R. Carroll
Independent Researcher through Hurtz Labs
Research Methods, Test Development, and Statistics
www.jrcresearch.net
www.ontvp.com
Cell: (650) 776-6613
Email: jrcarroll at jrcresearch.net
jrcarroll at hurtzlab.com
jrc.csus at gmail.com
<https://www.facebook.com/J.R.Car>
<https://twitter.com/jNammer><http://www.linkedin.com/in/jrcarroll>



On Mon, Mar 25, 2013 at 4:41 PM, Dinu Gherman
<gherman at darwin.in-berlin.de>wrote:


> I'm raising this question below again, since there was no response and

> with the current activities I'm afraid, it will be forgotten (but I do

> not want to raise it as a bug).

>

> Regards,

>

> Dinu

>

> > I'm trying to create an "encrypted" PDF in which users can view all

> > pages without knowing any password, but perform certain operations only

> > when they have the user password. With the code below from the user

> > guide (with minimal changes) I can always even view the content only

> > after entering the user password:

> >

> > from reportlab.lib import pdfencrypt

> > from reportlab.pdfgen import canvas

> >

> > enc = pdfencrypt.StandardEncryption("secret",

> > canPrint=False, canCopy=False)

> > c = canvas.Canvas("hello-enc.pdf", encrypt=enc)

> > c.drawString(100, 100, "Hello World")

> > c.showPage()

> > c.save()

> >

> > OTOH, the preview of the Python brochure does exactly that, let all

> > people see the content, but don't let them copy stuff e.g. without

> > a user password. See download on http://brochure.getpython.info

> >

> > Is there a way to achieve this with reportlab.lib.pdfencrypt?

> >

> > BTW, there is some space left for a ReportLab ad in the brochure...

> > ;-)

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20130325/58631ed2/attachment.html>


More information about the reportlab-users mailing list