Set the Passwords to PDF

Aug 13, 2006 (on the airplane to get back from WWDC06)
Masayuki Nii / msyk@msyk.net
Last Modified:

This package named 'Set the Passwords to PDF' installs the command line tool 'pdfauxinfo' and 'Add Auxiliary Info to PDF' Automator action. Automator action uses command line internally. You can set the user password and owner password to the PDF.

I had to make a pdf that has no password to open but require to correct password to print or copy. I used Adobe Acrobat to make such a pdf. Acrobat is the overall tool to edit pdf but sometimes it might be over-featured. Though I just wanted to set the password and privilege, I had to operate it with click by click. I thought we might have the other solution to complete any work in Mac OS X. I have searched the tool that is able to set the both passwords separately. There are some tools but almost all are more expensive than Adobe Acrobat. So I decided to develop such a tool because It will be way too easy to do by using PDFKit.

Actually PDFKit is powerful framework but sometimes so stiffness. Though I couldn't resolve any problem, the Cocoa Study members helped me. I appreciate them especially Kuroki-san. (He has given name same as me.) I could resolve some problems and my work came off as my original goal.

Download

'Set the Passwords to PDF' will work for Mac OS X v10.4.x.

User Package is just a pkg file to install one command and one action. The command will install to /usr/sbin/pdfauxinfo, and the action will install to /Library/Automator.

If you like to check the source codes, you can download from here. It has two projects and so on. These projects are for Xcode 2.4.

All materials from this page are is provided "as is" without any guarantee of warranty. Please use within your own risk. I have copyright for them but I won't ask you to pay the license fee. I welcome your advices and modifications.

'Add Aux Info to PDF' Automator action

'Add Aux Info to PDF' Automator action can set the passwords and some attributes. This action accepts the file or folder input, but it works just pdf and one pdf (not as list input). After processing the action, new pdf file will create on /tmp directory. Original pdf file isn't touched and still keep same as prior to the processing.

This action uses the command line tool 'pdfauxinfo'. This command line tool is installed by the above package file and works on Mac OS X v10.4 or later, so this action requires the same version of Mac OS X.

It may have to explain the UI of this action. There are five text fields and all are meaning as each label. Two password fields hide the typed letter to replace the dot character. If you enter each field, the strings will be set to the input pdf. If you don't enter the field, the relevant parameters will not set to the pdf. It means that null string will not set to the pdf and nothing to set it.

There are two checkboxes, then please pay attention to the status of checkbox. Normally checkbox has two states, on or off. The setting for these permissions has three states, permit, not permit, or unspecified. The state 'unspecified' means that it doesn't set by this action and expected the same behavior from the original input pdf. Both checkboxes are tri-state mode. The following picture shows that every states for checkboxes. From top, permit, not permit and unspecified. You can cyclically change the state of checkbox by clicking

'pdfauxinfo' Command Line Tool

The command line pdfauxinfo can add the passwords and some attributes to the pdf. It is for Mac OS X only, and needs version 10.4 or later. You can set the user and owner password, permission to printing and copying. In addition to password and privilege future, you can set the tile, author and creator information.

Why does it need as the command line? The answer is clear. We can use the command line tools for making a solution by using shell script.

The usage of pdfauxinfo command is following. You can see the same information by using --help option.

$ pdfauxinfo --help
Description:
  pdfauxinfo can set the auxiliary information to PDF file using PDFKit in Cocoa.

Parameters:
  --sourcePDFFile, -i Input_File_Path            Original PDF File.
  --convertedPDFFile, -o Output_File_Path        Converted PDF File.
  --author, -a Author_Name                       Author info of PDF.
  --creator, -k Creator_Name                     Creator info of PDF.
  --title, -t Title_of_Document                  Title of PDF.
  --userPassword, -u User_Password               User Password for document.
  --ownerPassword, -x Owner_Password             Owner Password for document.
  --permitPrinting, -p [YES|true|1|NO|false|0]   Permission for printing the document.
  --permitCopying, -c  [YES|true|1|NO|false|0]   Permission for copying the text.
  --debug, -d                                    Debug mode.
  --help, -h                                     Show this message.

For the option permitPrinting and permitCopying, YES or true or 1 means permitting, 
the others means not permitting.

You need to specify the sourcePDFFile and convertedPDFFile options.

pdfauxinfo works just only Mac OS X Tiger or later.

You need to specify both --sourcePDFFile and --convertedPDFFile, and they will be different file path. If --convertedPDFFile is already existing, pdfauxinfo will overwrite it. Standard input and output are not available now.

The return value 0 means that pdfauxinfo create the converted pdf file successfully. The return value 1 means you don't specify both sourcePDFFile and --convertedPDFFile. To check what means the other return value, please refer the source code.

Debug mode will show the Auxiliary Dictionary to set the pdf on the standard output. It simplly uses CFShow.

Workaround for Auxiliary Info

We can set the two passwords to pdf, user password and owner password. In Japanese version of Acrobat, user password is just meaning 'the document password', and owner password is just as the privilege password. The behavior of the passwords and the permissions depends on the pdf reader. I just need to check on the Mac OS X, so I checked about Preview 3.0.7(Mac OS X 10.4.7) and Adobe Reader for Mac 7.0.8. There is just a permission to print in the following table, it will be same behavior to the permission to copy.

SituationBehavior
User PasswordOwner PasswordPermission to printPreview 3.0.7Adobe Reader 7.0.8
YesYesYesTo open the document, we need to enter password. It doesn't matter which password. After that it can print without entering password.
YesYesNo
OpeningPrinting
Input user password.Getting permision after input owner password.
Input owner password.Already permitted.
Input user or owner password on opening, it open and can not print.
YesNoYesTo open the document, we need to enter user password. After that it can print without entering password.
YesNoNoTo open the document, we need to enter user password. After that it can not print.
NoYesYesIt can open without password, and it can print.
NoYesNoIt can open without password. Try to print, need to owner password on the sheet.It opens without password, and it can not print.

I couldn't set just user password to pdf, so I need to set the owner password too. For to avoid the authentication, pdfauxinfo sets the owner password to "" when the user password is set and owner password is not set. I don't know the reason for above behavior, I predict that it's kind of the matter of framework.

As Preview application, it uses owner password for granting the permission, and it can change the permission to print and copy. As Adobe Reader, it might not have kind of future, or it's available on limited circumstance.