How to distill / rasterize a PDF in Linux

We have a printer at our office that prints PDF files from a USB stick. It prints most files okay, but it has problems with some, especially ones generated with Latex. Some PDFs it simply refuses to print, some PDFs it prints with courier-type font, and some it prints fine except for equations.

I'm looking for a way to "distill" PDFs into a dead-sure format to print. Either by simplifying / normalizing the PDF to the point that any renderer will render it correctly, or by simply making each page a 600dpi raster image in the PDF. (I could split the PDF into individual raster images and combine them manually, but I want something scriptable.)

The output file size doesn't matter, as long as it's sure to print, has A4 paper size (or the original) and 300~600dpi resolution.


After unsuccessfully trying some options to render the fonts as outlines (including this question and pstoedit), I figured out a way to easily convert the PDF into rasterized form using ImageMagick:

convert -density 600 +antialias input.pdf output.pdf

This creates a PDF rendered at 600 dpi, with antialias turned off (unnecessary at that resolution).

The output files are huge (~30 MB for an 8-page document) and extremely slow to print, but should work as long as the printer has enough memory to render the content.


This is an improvement on the Accepted answer: it also lets gs optimize the file so that it's not so huge, and fixes an occasional compatibility problem: As a bash script (ie put this in your ~/.aliases and open a new terminal window):

rasterizePDF() {
echo "Usage: rasterizePDF fromfile.pdf : this makes a 300dpi raster version. And optimizes it with ghostscript. Output is fromfile.pdf-scanned.pdf"
tmpfile=$(mktemp).pdf
echo "Creating raster version... (in $tmpfile)"
convert -render -density 300 $1 $tmpfile
echo "Optimizing to shrink pdf file..."
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$1-scanned.pdf $tmpfile
evince $1-scanned.pdf&
echo "Finished; launched viewer."
}

I use this very frequently: any time I annotated a PDF or sign an autograph on one, etc, and want to fix those edits or make them ultra-portable.

(The script calls evince at the end. That's a PDF viewer. You can replace that with your favourite PDF viewer).


Using imagemagick is, in my experience, not stable with high resolutions and/or big files. Many printers can do 1200 dpi and up, so the rasterized file should have similar resolution. A better solution is to use pdf2djvu which is faster, more robust, and even creates files with a size that often rivals the original PDF at 1200 or 2400 dpi. These files can be viewed and printed using okular or evince.

Example:

pdf2djvu -d 2400 file.pdf > rastered.djvu