PDF Rendering

PDF rendering in Safari

While HTML has gone a long way, if you want reasonably stable rendering of pages, PDF is still king of the hill. But being widespread does not ensure stability.

If you look at the these two renderings, in particular around the feet, you will see some pretty weird differences (click to see full-size pictures). The first is a rendering in Safari, while the second was rendered in Chrome. You can notice many gray artefacts in transparent areas of the second image, the colours are also overly saturated.

PDF rendering in Chrome

These differences seem to be only the tip of the iceberg: at this year’s CCC there was an interesting presentation about hybrid file formats, including PDF files that would render different things depending on the viewer.

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…