Set Passwords and Infomation to PDF (version 3)

Oct 11, 2015
Masayuki Nii / msyk@msyk.net
Last Modified:

Quick Link: Download Installer Package, this is made in macOS High Sierra at Feb 3, 2018.

"Set Passwords and Infomation to PDF" can set User/Owner passwords and Title/Subject/Keyword/Author/Creator information to PDF file. It contains the command line tool 'pdfauxinfo' and 'Add Auxiliary Info to PDF' Automator action, and therefore it's for Mac OS X. Automator action uses command line internally. The version 3 is for OS X El Capitan or later. If you need to use it for previous OS X, please check the version 1 set, or version 2

Background

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 can edit any pdf but sometimes it might be over-featured. Though I just wanted to set the password and privilege, I had to operate Acrobat 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've decided to develop such a tool because It will be way too easy to do by using PDFKit. It was 2006 and I've built up for Tiger. Mac OS X Leopard came out on October 2007 and some users reported me about incompatibility. I've modified for Leopard and released on March 2008 (Thanks to Mike Bowie for testing.) In 2015, OS X El Capitan was revealed and pdfauxinfo didn't work again because the System Integrity Protection applied. Ver.3 was made for El Captain (Thanks for Tim Dawson.)

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 Passwords and Information to PDF (version 3)' will work for Mac OS X v10.11 (El Capitan) or later.

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

If you like to check the source codes, the repository is here.

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 passwords and some information. 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 with above installer and works on OS X v10.11 or later, so this action requires the same version of Mac OS X.

There are seven text fields in the panel of the action and all are meaning as each labels. Two password fields hide typed letters 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 them.

There are two checkboxes for permissions and one checkbox for the bit length of encryption. The '128 bit encryption' checkbox allows to encrypt the source PDF with 128 bit. If you don't check it, the source PDF will be encrypted by 40 bit.

Please pay attention to the status of checkboxes for permissions. 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 as 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 passwords and some information to the pdf. It is for Mac OS X only, and needs version 10.11 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.

$ /usr/sbin/pdfauxinfo --help
Description:
  pdfauxinfo can set the auxiliary information to PDF file using PDFKit in Cocoa.
  This is the version 3.x command line tool for Leopard only.

Parameters:
  --sourcePDFFile, -i Input_File_Path            Original PDF File path.
  --convertedPDFFile, -o Output_File_Path        Converted PDF File path.
  --author, -a Author_Name                       Author info of the converted PDF.
  --creator, -k Creator_Name                     Creator info of the converted PDF.
  --title, -t Title_of_Document                  Title of the converted PDF.
  --userPassword, -u User_Password               User Password for the converted PDF.
  --ownerPassword, -x Owner_Password             Owner Password for the converted PDF.
  --permitPrinting, -p [YES|true|1|NO|false|0]   Permission for printing the converted PDF.
  --permitCopying, -c  [YES|true|1|NO|false|0]   Permission for copying the text.
  --subject, -s Subject                          Subject for the converted PDF.
  --keyword, -k Keyword,Keyword...               Keywords for the converted PDF, divide by ','.
  --encryptionKeyLength, -e length               Encryption key length by bit.
  --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.

The encryptionKeyLength option must be a multiple of 8 between 40 and 128.
If this option is not specified, 40 bit will use to encrypt.
If this option is set to other than 40, 128 bit RC4 will use to encrypt.

Required options are sourcePDFFile and convertedPDFFile.

pdfauxinfo v3.x works just only OS X El Capitan or later.

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

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 simpley uses CFShow.

Workaround for Auxiliary Info

We can set 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 as the privilege password. The behavior of passwords and the permissions depends on pdf reader. I've checked the behavior in Preview 4.1(Mac OS X 10.5.2) and Adobe Reader for Mac 8.1.2. There is just the permission to print in the following table, it will be same behavior to the permission to copy.

SituationBehavior
User PasswordOwner PasswordPermission to printPreview 4.1Adobe Reader 8.1.2
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.