How to distill / rasterize a PDF in Linux

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.


I think my current preferred way to do it is:

  1. Use pdftoppm to convert the PDF file into a series of images.

    $ pdftoppm source.pdf output -png

  2. Use img2pdf to create a pdf file out of those images.

    $ img2pdf *.png -o output.pdf

The good news is you can create a bash script to automate the whole process for you.

Here is a bash script that will distill all pdf files within a directory and preserve the originals in a new directory "originals".

#!/bin/bash

mkdir "originals";
for filename in ./*.pdf; do
    pdftoppm "$filename" output -png
    mv "$filename" ./originals
    img2pdf *.png "-o" "$filename"
    rm *.png
done

Credits: img2pdf answer & pdftoppm answer & bash script help: 1 & 2

(Side note) You can install img2pdf using:

$ sudo apt install img2pdf