Unlocking PDF files


People writing RPG scenarios seem to have two bad habits: using weird fonts, and distributing their texts in password protected PDF files. Very often, the weird font is either not included in the PDF, or so corrupt that any modern operating system will flat out refuse to load it; when the document is displayed, poor Helvetica is forced into strange bounding boxes, and the result is basically unreadable. Because the document is copy-protected, one cannot simply copy-paste the text into a text editor to simply read it.

Thankfully, it is possible to get to the text by making a round-trip using ghostscript. Please only use this to read documents, and not to copy them or do anything nefarious. On Mac OS X the sequence is the following (assuming you have MacPorts installed).

sudo port install gs
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf

Where encrypted.pdf is your encrypted pdf file. On exit, unencrypted.pdf will contain the unencrypted text, the layout will still be broken (although often makes things less evil in the process), but you will be able to copy-paste the text. Beware that depending on the tool that produced the PDF file, there might be weird spaces all over the text, and bits of text will be moved into random places…

Liked it? Take a second to support Thias on Patreon!

Flattr this!

Leave a Reply