[reportlab-users] Encryption in pdf

Robin Becker robin at reportlab.com
Fri Sep 11 05:03:29 EDT 2009


Andrea Cappelli wrote:

> Hi list,

> yesterday I tried to create an encrypted pdf, as stated in paragraph 4

> of readme.pdf, but it doesn't work me regarding the options like

> canPrint, canCopy, etc.

>

> The output is encrypted and requires a password to be opened (unless i

> specifies only the ownerPassword, in this case as stated no password for

> opening is required) but I can print and copy from the document

>

> I'm usign reportlab 2.3 on Ubuntu 9.04 (python 2.6 ) and the following

> piece of code:

>

> from reportlab.pdfgen import canvas

> from reportlab.lib import pdfencrypt

> enc=pdfencrypt.StandardEncryption("","owner_pass",canPrint=0,canCopy=0)

> def hello(c):

> c.drawString(100,100,"Frase di test che non dovrebbe essere

> copiata")

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

> hello(c)

> c.showPage()

> c.save()

>

........

well I tried this

> from reportlab.pdfgen import canvas

> from reportlab.lib import pdfencrypt

> enc=pdfencrypt.StandardEncryption("user_pass","owner_pass",canPrint=0,canCopy=0)

> def hello(c):

> c.drawString(100,100,"Frase di test che non dovrebbe essere copiata")

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

> hello(c)

> c.showPage()

> c.save()


ie use a user as well as an owner password. The document then asks for a
password. If you use the user password the print menu entry is missing. At least
in my acrobat reader. The 1.7 manual says this


> If a user attempts to open an encrypted document that has a user password,

> the application should prompt for a password. Correctly supplying either

> password enables the user to open the document, decrypt it, and display

> it on the screen. If the document does not have a user password, no password

> is requested; the application can simply open, decrypt, and display the

> document. Whether additional operations are allowed on a decrypted document

> depends on which password (if any) was supplied when the document was

> opened and on any access restrictions that were specified when the

> document was created:


I think the idea is this. If you have the owner password effectively there are
no restrictions. If you have the user password then the restrictions should
apply. If you specify only an owner password then the reader is allowed to
decrypt it. Seems a bit strange, but that's the way it is.
--
Robin Becker


More information about the reportlab-users mailing list