Set public domain content free from locked PDF files

Lately I’ve been digging around online to find old genre short stories written in the 19th and early 20th centuries. In many cases it’s clear that the works have passed into the public domain, at least here in the U.S., but in other cases there’s a questionable copyright claim, as when a modern publisher slaps a new copyright on what appears to be public domain, and you can’t find any evidence of said registration with the Copyright Office.

Whether such cases are due to idiocy or deliberate copyfraud, they hurt the consumer. It’s prohibitively expensive for the average private citizen to have to engage the Library of Congress as well as hire a copyright attorney (which, no kidding, is what the Copyright Office recommends) just to confirm that he has the right to do what he wants with something published in 1925. Even then, if the work was first published outside the U.S. then it may be nearly impossible to determine its true copyright status.

Which leads me to the problem of locked PDF versions of century-old works. I’m now in the possession of half a dozen PDFs of old short stories that various websites offer for free, and yet those files have been password protected to prevent me from printing, copying, or otherwise gaining direct access to the text. In the most extreme cases, the person who created the PDF file has, for reasons known only to him and the functionally retarded demon who guides him, added his own copyright claim to it. Seriously, people should just be hit with sticks sometimes.

Remove that PDF’s sham DRM with MuPDF!

(That may be the worst subheading ever written.)

Fortunately, Robert Brewer at Excited Curiosity explains that you can use a free open source PDF toolkit called MuPDF to unlock password protected PDF files. There are MuPDF viewers for Windows and Linux at, but For OS X you have to use the command line (i.e., the Terminal app found under Applications>Utilities). Everything that follows is for OS X users.

First download the OS X binary from, unarchive it, and put the resulting folder wherever you like. Then in Terminal, use the “cd” command to navigate to that folder, and then run the “pdfclean” command on a locked file and in seconds, you’ll have a new unlocked version. Here’s an example of how to run the command if you have the MuPDF folder in your home directory and the locked PDF file on your Desktop:

./pdfclean ../Desktop/lockedfile.pdf ../Desktop/newnameforfile.pdf

If you’re not used to Terminal, here’s a quick introduction that will teach you the basics. Pretty much all you need to know to use MuPDF is how to type the full paths of the MuPDF folder and of the locked PDF file, and the command “cd” to change directories. (The command “ls” to list the contents of your current directory is also helpful.) You can also check out this comment on Brewer’s blog for more help.

Using OS X? Here’s a contextual menu shortcut for MuPDF

I was excited about finding this free solution to the bogus DRM problem, but I wanted an easier way to use it in the future without having to launch Terminal each time. I created a simple workflow service in Automator that I can access via the contextual menu when I click on a file. Now when I download a PDF and find that it’s locked, I simply right-click the document and select “UnlockPDF” from my Services menu, and a clean version appears next to the original.

Here’s the code I used to create the service. Note that I wrote this using Automator 2.2.1; when I shared a similar tip last year for KindleGen, I discovered that some readers couldn’t replicate my instructions because they were using older versions.

on basename(thePath)
	if thePath ends with "/" then
		set nameIndex to -2
		set nameIndex to -1
	end if
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set thePath to text item nameIndex of thePath
	set AppleScript's text item delimiters to ASTID
	return thePath
end basename

on getdir(theFileName)
	set theReversedFileName to (reverse of (characters of theFileName)) as string
	set theOffset to offset of "/" in theReversedFileName
	set thePrefix to (reverse of (characters (theOffset + 1) thru -1 of theReversedFileName)) as string
	set theSuffix to (reverse of (characters 1 thru (theOffset - 1) of theReversedFileName)) as string
	return thePrefix
end getdir

on run {input, parameters}
	set myFile to quoted form of POSIX path of input
	set newFile to basename(POSIX path of input)
	set newPath to getdir(POSIX path of input)
	set finalPath to (newPath & "/u-" & newFile)
		do shell script "../../Applications/mupdf-0.7-darwin-i386/pdfclean" & " " & myFile & " " & finalPath
	end try
	return input
end run

Quick instructions:

  1. Launch Automator and create a new Service workflow.
  2. At the top of the composition area, change “Service receives selected [dropdown]” to either “files or folders”, “folders”, or “PDF files”. Change the other dropdown to “Finder”.
  3. In the Library pane on the left, click the Utilities directory, then find the “Run Applescript” action and drag it into the composition area.
  4. Select all the default code in the “Run Applescript” box and delete it.
  5. Paste the above code in. Be sure to edit the path to the MuPDF folder so that it’s correct for your situation.
  6. Click the hammer icon to compile the code.
  7. Save the service under whatever name you like. I chose “UnlockPDF” to make it easy to find months from now when I’ve forgotten all about how I did this.

Because I’m a pretty bad scripter, I’m sure this isn’t the most elegant way to do this. If you can improve on it—particularly if you can fix it so that it can batch process an entire folder of PDF files—please let me know and I’ll update the script.

(Frozen book illustration credits: Ice Block, Risager; Old Book, HoskingIndustries)

This entry was posted in DIY, free, how to, online, resources, services, software and tagged , , , , , , , , , , , . Bookmark the permalink.

3 Responses to "Set public domain content free from locked PDF files"

Leave a reply

7 − = three