Making PDFs usable
June 3, 2009 at 11:23 PM by Dr. Drang
About a year ago I wrote a post describing, rather elliptically, my troubles with DRM’d PDF files bought from a standards agency and how I generated unencumbered PDFs from them. Today I had even more trouble with DRM’d PDFs bought from another source, and I’ve decided I won’t be so elliptical in writing about the solution.
In a nutshell, the problem is that the PDFs I bought require a copy of Adobe Reader with the FileOpen plugin. The intention of the DRM is to lock the PDF to a single computer, but it ends up locking the file to a particular version of Reader. If I upgrade Reader when Adobe releases a new version, the PDF will think it’s on a new computer and will refuse to open. This is not a theoretical concern; it happened to me last year.
The PDFs I bought today caused even more trouble. At some point, either while scrolling through the file or while printing it, Reader would freeze up, giving me the spinning beachball of death, and I’d have to Force Quit the application. So with these files even the current version of Reader couldn’t be trusted to open them and keep them open, which means that I just paid for something broken. Ironically, I’m able to fix these files by breaking them further. Here’s how I do it.
The method depends on a clever hack I learned from this Linux Forums discussion. The hack involves Ghostscript and its PostScript-to-PDF conversion capabilities. I’ve learned that it won’t work with the latest Ghostscript, but will work with version 8.15, which is still available from SourceForge. I downloaded and expanded the source code into a ghostscript-8.15
directory in my home folder, then built it using
cd ~/ghostscript-8.15
./configure
make
With this, I had a fully-functioning Ghostscript system in my home directory that was ready for the Linux Forums hack.
I opened ~/ghostscript-8.15/lib/gs_pdfwr.ps
and changed Line 603 from
{ currentdevice .devicename dup /pdfwrite
to
{ currentdevice .devicename dup /pdfwritexyz
and saved the file. (It’s not really important what’s appended to /pdfwrite
as long as the device name is changed.) Now that this one-time preparation is out of the way, I’m set up to create unDRM’d PDFs.
The first step is to use a trick involving the Mac’s printing system. When a file is sent to a printer, the printer driver first creates a spool file in the native language of the printer, then sends it along to the printer. After the file is printed, the spool file is deleted. If the printer is paused, however, the spool file will not be deleted because the print job isn’t finished. Getting that spool file is the key to creating an unencumbered PDF.
It just so happens that my default printer is a PostScript printer, so the spool file is PostScript, a close cousin of PDF and the format Ghostscript was written to handle. I open the Print & Fax Preference Pane,
choose that printer and open its Print Queue,
and Pause the printer.
Now I open the DRM’d PDF in Adobe Reader and give it the Print command. For DRM’d documents, Reader doesn’t use the standard Mac Print sheet, because that would let me directly create a new, unencumbered PDF from the Save as PDF… command. Instead, it throws up this piece of shit
which doesn’t let me choose the printer or double-sided printing or any other nice feature. But it does create the spool file, which is now in /private/var/spool/cups/
.
Unfortunately, I can’t just open /private/var/spool/cups/
in the Finder and grab the spool file. That directory is for root access only. But I can get at it from the Terminal:
cd /private/var/spool
sudo ls -lt cups/
After I give my administrative password, the second command lists all the files in the cups
subdirectory in reverse chronological order. The PostScript spool file will be the big file near the top of the list, and will have a name like d00355-001
. The command
sudo cp cups/d00355-001 ~/Desktop
will put a copy of that file on my Desktop. It’s a PostScript file, but it still contains the DRM DNA. I delete the print job from the queue and unPause the printer.
(I am, admittedly, in a very good position because my default printer is PostScript. If it weren’t, I’d create a new printer—a dummy printer not associated with any real hardware—in the Print & Fax Preference Pane, assign a PostScript driver to it, and temporarily set it as the default printer. That would force Reader to create the PostScript spool file I need for the last step. After I had the spool file, I’d reset the default printer to whatever it was before.)
Creating a normal PDF requires just one more step with the modified Ghostscript system.
cd ~/Desktop
~/ghostscript-8.15/lib/ps2pdfwr -dCompatibilityLevel=1.2 d00355-001
I now have a new file called d00355-001.pdf
on my Desktop, and it is, amazingly, DRM-free. I can open it in Reader now, and I’ll be able to open it in future versions of Reader, too. I can open it in Preview, which is even better since that’s my default application for PDFs (and, frankly, a much better program than the Mac version of Reader). It is, in short, a file that works, something I didn’t have before.
Apart from one or two changes in the directories, this approach should work as well for a Linux computer as it does for a Mac. I’m pretty sure it won’t work on Windows unless something like Cygwin is installed. It’s possible that the Windows version of Reader is more robust than the Mac version, making all this rigamarole unnecessary. It’s also possible that I’ll sprout wings overnight and fly to the Moon. I’ll keep you posted.