Recently I needed to demonstrate proof of purchasing something via my credit card statement. Easy enough, I download my most recent statement as a PDF file from American Express. Then I wanted to use Adobe Acrobat Pro’s nifty redaction features to redact all the irrelevant information from the appropriate page of the bill. Except Amex has decided that the statement should be a protected PDF, which means you can view it but cannot change it. This is of course totally bogus DRM, it’s my statement afterall! I suppose they hope to curb statement forgeries, but as anyone akamai knows: if I can view it, I can edit it. I think Preview.app on Mac OS X used to ignore DRM and let you edit protected PDFs, but doesn’t seem to on Snow Leopard.
I hunted around for a tool to unlock the PDF. There are lots of tools for Windows, which didn’t interest me. One person suggested opening the PDF and “printing” it to a PDF, but Adobe has disabled those features of the Print dialog box on Mac OS X (presumably since it would allow trivial circumvention of the DRM).
PDFKey Pro looks like a reasonable option for Mac OS X, but it is $25 which seems kinda steep for a single use. They have a downloadable demo, but it will just create an unlocked version of the first page of the PDF, which wasn’t the page I wanted. And of course I can’t edit the source PDF because it is protected, so the demo wasn’t useful to me.
Then I came upon MuPDF, which is a “lightweight PDF viewer and toolkit written in portable C”. It has an X11 GUI component, as well as command line tools. One of the command line tools is “pdfclean”, which will remove the DRM from a PDF.
Unfortunately, MuPDF isn’t in MacPorts yet, so I had to compile it by hand. It uses the Perforce jam tool instead of make, and has three library dependencies: zlib, libjpeg, and freetype2. Luckily, all of these are available in MacPorts, so I was able to install them and then edit the Jamrules file to point at the MacPorts location. Here is the updated section of Jamrules:
if $(OS) = MACOSX
{
Echo Building for MACOSX ;
BUILD_X11APP = true ;
CCFLAGS = -Wall -std=gnu99 -I/opt/local/include -I/opt/local/include/freetype2 ;
LINKFLAGS = -L/usr/X11R6/lib -L/opt/local/lib ;
LINKLIBS = -lfreetype -ljpeg -lz -lm ;
APPLINKLIBS = -lX11 -lXext ;
if $(BUILD) = debug { OPTIM = -g -O0 -fno-inline ; }
if $(BUILD) = release { OPTIM = -O3 ; }
if $(HAVE_JBIG2DEC) { LINKLIBS += -ljbig2dec ; }
if $(HAVE_OPENJPEG) { LINKLIBS += -lopenjpeg ; }
}
pdfclean worked like a charm, removing the DRM from the statement. After that I was able to redact the statement without incident.
Perhaps in my copious spare time I will make a MuPDF portfile for MacPorts, but until then perhaps this will help others who want an open source way to remove bogus PDF DRM.
May 17, 2010 at 8:42 pm |
It seems that there is a version precompiled for Mac on the muPDF Website:
http://ccxvii.net/mupdf/download/mupdf-0.5-macosx.tar.gz
Thanks for this post, very useful. I was desperate to find an alternative to PDFkey.
May 17, 2010 at 10:03 pm |
Thanks for pointing that out! I could have sworn I looked there and despite some references to the Mac OS X executable, I couldn’t find it. Perhaps I just missed it.
July 26, 2010 at 5:05 pm |
The link above is broken. Found it under “archive”:
http://ccxvii.net/mupdf/download/archive/mupdf-0.5-macosx.tar.gz
July 26, 2010 at 5:17 pm |
Thanks for pointing that out Mitchell. It appears that the developer is no longer making Mac OS X builds.
November 15, 2010 at 6:42 am |
Excellent! It worked for me and thank you for the post.
November 22, 2010 at 2:19 pm |
Can someone walk me through how to build or compile this? I have never done this before. Thank you.
November 22, 2010 at 3:35 pm |
Good news Steve, there are now downloadable executables for Mac OS X that you can run directly without compiling: http://ccxvii.net/mupdf/download/mupdf-0.7-darwin-i386.tar.gz
March 30, 2011 at 7:13 pm |
Boy, did this save my butt! (Gotta love the Intel manuals: so big that Kinko’s can’t bind them, and yet one is prohibited from chopping the PDF into smaller chunks!) One note is that the Mac binary has moved to: http://mupdf.com/download/archive/mupdf-0.7-darwin-i386.tar.gz
Thanks again for this!
June 16, 2011 at 11:45 am |
Ya MuPDF Worked awsome!
Thanks Guys!
July 8, 2011 at 9:34 am |
how do you install the mupdf folder once it;s downloaded? I can’t find step by step instructions anywhere.
Walkthrough please!?
July 8, 2011 at 10:44 am |
mupdf is a group of command line programs. If you have downloaded the binary version from http://mupdf.com/download/archive/mupdf-0.7-darwin-i386.tar.gz and then double-clicked the archive, you should have a folder called “mupdf-0.7-darwin-i386″. The command line tools are in that folder. If you’ve never used the Mac OS X command line, you’ll want to Google some instructions (outside the scope of this comment).
From the command line (shell), you will need to type “cd name-of-directory” where you type in the name of the directory where your mupdf folder is. Then type “cd mupdf-0.7-darwin-i386″. Once there, you can run any of the commands by typing “./commandname”. For example, if you want to unlock a protected PDF, you would type “./pdfclean locked.pdf unlocked.pdf” where locked.pdf is the name of your locked PDF file (which might need the whole path to the file if it is in a different directory) and unlocked.pdf is the name you want to save the unlocked version as.
I hope this helps.
November 30, 2011 at 7:22 am
Thank you Robert!
It helped a lot for me!
July 11, 2011 at 4:58 am |
champion. thanks alot that’s all I needed!
July 11, 2011 at 5:04 am |
champion. thanks alot that’s all I needed!
only thing is you put in 0.7-darwin-i386. I have “mupdf-0.5-macosx”. is the darwin version for os X? Is it more recent than the 0.5 i have?
July 11, 2011 at 11:59 am |
Yes, darwin is the name for Apple’s open source Unix that underlies Mac OS X. 0.7 is a newer version, but 0.5 should also work fine for unlocking a PDF (in my experience)
July 17, 2011 at 8:54 pm |
YAY! Thank you all.
July 26, 2011 at 6:25 am |
I’ve got: ” dyld: unknown required load command 0×80000022
Trace/BPT trap “
August 26, 2011 at 1:28 am |
Thanks a lot, you’ve helped me so much. Tried many tools, and they didn’t work or were to pricey for a one time use. pdfclean made my day.
August 30, 2011 at 10:54 pm |
Really a useful post! And i can add one more useful software – Recover PDF Password. It helped me when i couldn’t open Pdf file, cause it was protected with user password. Without any problems I removed a password. Who have the same problem, just look
http://mac.eltima.com/pdf-password-recovery.html
October 9, 2011 at 8:42 pm |
Thanks to author, for a good post and
thanks for tha last advice from Darun. I tried this tool and i use it almost every day (i have a usial work with PDF docs).
October 12, 2011 at 12:57 pm |
please, please create a macport for this
November 19, 2011 at 2:28 am |
Thanks for this. The number of academic publishers that stop you copying and pasting from articles is unbelievable. It has to be counter-productive. I’ve got over a thousand papers in my collection and at least 20% are impaired in this fashion. Not anymore!
Speaking of which can anyone tell me how to write a short shell script that would recursively use the pdfclean command on 1000 files?
December 5, 2011 at 7:22 am |
[...] Robert Brewer at Excited Curiosity explains that you can use a free open source PDF toolkit called MuPDF to unlock password protected [...]
December 27, 2011 at 1:28 am |
can anybody tell me the same software for windows? I’m planning to buy this one, has anyone tried it. Check the link
http://www.unlockapdf.com
December 29, 2011 at 10:22 am |
Adobe For Mac…
[...]Unlocking a protected PDF on Mac OS X « Seize the Moment of Excited Curiosity for the Acquisition of Knowledge[...]…
January 4, 2012 at 10:38 am |
On a mac, you can run the following command to create “unlocked.pdf” from “locked.pdf”:
gs -sOutputFile=unlocked.pdf -sDEVICE=pdfwrite -dNOPAUSE -dbatch -q locked.pdf </dev/null
January 4, 2012 at 11:04 pm |
What an awful link, Peacemahn!
Great post, Robert!
By the way, I have some proposition to you! Could you contact me ASAP?
I think you will see my e-mail in the comment form
April 12, 2012 at 12:32 am |
Thank you thank you thank you! I’ve been working on a script using pdfkey for a few days.. turns out it was actually breaking my pdfs. I was about to go insane when I found this post.. MuPDF is PERFECT
And it installed flawlessly with homebrew
April 12, 2012 at 5:47 am |
Hey, guys! If you want to use an efficient PDF Recovery tool – I can offer you a coupon code RECOVER-PROMO-15 with 15% discount. You can try this toll going to http://mac.eltima.com/pdf-password-recovery.html