PDFPermissions blank UserPassword

I’m trying to create a PDF that allows users to open/copy/print without a password, but has a password for modifying. From the documentation on PDFPermissions, it appears I should be able to do that. No matter what I try, the document requires a password to view. I’ve tried this in Apple Preview, Adobe Reader, Nitro PDF Pro, PDF Expert, etc.

Var pdf As New PDFDocument
pdf.Compressed = True

Var per As New PDFPermissions("ownerPassword")
per.AllowCopyingContents = True
per.AllowModifyingContents = False
per.AllowPrinting = True
pdf.Permissions = per

I’ve also tried both of the following:

Var per As New PDFPermissions("ownerPassword", "")
per.UserPassword = ""

What am I missing?

I think that once it has a password with some denial of access, it demands identification (asks for a password) to open (before view)

That appears to be the case. That said, if I do a Save As in Preview, I have the ability to allow opening/printing/copying without a password and still have modifying password protected.

If you can do this, and can’t mimic in Xojo, you should open an Issue report. Maybe a bug.

1 Like

Will do, thanks for the feedback Rick!

1 Like

Some technical info:

When you protect your PDF documents with passwords you can optionally specify a set of permissions. The permissions determine which kind of access the user password will provide. Using the permissions you can prohibit the user from printing and using cut and paste operations. The table below shows an overview of the 32bit signed int that carries this information. This table is part of the PDF reference (third edition).

1-2 Reserved; must be 0.
3 (Revision 2) Print the document.
(Revision 3) Print the document (possibly not at the highest quality level, depending on whether bit 12 is also set).
4 Modify the contents of the document by operations other than those controlled by bits 6, 9, and 11.
5 (Revision 2) Copy or otherwise extract text and graphics from the document, including extracting text and graphics (in support of accessibility to disabled users or for other purposes).
(Revision 3) Copy or otherwise extract text and graphics from the document by operations other than that controlled by bit 10.
6 Add or modify text annotations, fill in interactive form fields, and, if bit 4 is also set, create or modify interactive form fields (including signature fields).
7-8 Reserved; must be 1.
9 (Revision 3 only) Fill in existing interactive form fields (including signature fields), even if bit 6 is clear.
10 (Revision 3 only) Extract text and graphics (in support of accessibility to disabled users or for other purposes).
11 (Revision 3 only) Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if bit 4 is clear.
12 (Revision 3 only) Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this bit is clear (and bit 3 is set), printing is limited to a lowlevel representation of the appearance, possibly of degraded quality.
(See implementation note 16 in Appendix H.)
13-32 (Revision 3 only) Reserved; must be 1.

A number of the bits listed above are reserved and must be 0 whereas others must be 1. If you combine all the mandatory reserved bits (many are set as 1) you get a decimal value of -3904. The number is negative because it is a signed integer. With that number as a base you can add the bit values of the permissions you want. Let’s say you want the user to have print and copy permissions then you add bit 3 for printing and bit 5 for copy. The permission value is then -3904 + 4 + 16 = -3884.

It is important that you specify an owner password when using this security feature. User and owner passwords must be different. If they are the same then the user will have owner permissions, which means that the permission settings have no effect. You can leave the user password blank if you wish.

1 Like

The table makes sense to me, however is there any way for me to apply this information in Xojo?

This table MAY be helpful for Xojo engineers analyzing your case, and inspecting the PDF sample created by you using Xojo and your PDF sample saved using other tools working as you expect.

Additionally, to them: Sponsored ISO standards for PDF technology – PDF Association

1 Like

It looks like a bug at design. Xojo is creating a protected document that requires Owner or User password to open.

Please post here the Issue number when you create one. Thanks.

1 Like


Thanks for all the input everyone!


Yep, my fault when generating the permissions object. Found it and will be fixed.


Amazing! Followup question: what type of printing will AllowPrinting enable? From the chart above, it looks like one can enable low res and full res printing, depending on the bits set. For my current project, this won’t make a difference, but I could see instances where it would…

Hi @David_Vrooman

It allows full res printing.

1 Like

But, unfortunately not UTF8 :frowning:

Hi @Ian_Kennedy

We know about it and, in fact, there are a couple opened Issues about it.

Please, this one is about PDFPermissions, so let’s keep the comments on the topic :slight_smile:


Excellent. Thanks Javier