Home

PDF to PNG for Black and White Diagrams

Use ImageMagick on the Unix command line as shown below to convert a PDF to a PNG. It works well on black and white diagrams.

convert -density 600 input.pdf -alpha off -quality 95 output.png

-density: controls "geometry size," which is like pixel density.

-alpha: The "off" option replaces a transparent background with a white one.

-quality: Tens digit is zlib compression level. Ones digit is PNG filter type. More about this on the ImageMagick reference page.

My goal was to preserve details in schematic and drawing PDFs I have. The density should be adjusted for desired results, since it depends on how dependent the diagram is on pixel count. The quality factor of 95 specifies a zlib compression of 9 (highest compression) with an adaptive PNG filter 5. The resulting file size is pretty good. I tried JPEG, which resulted in mediocre quality and large file sizes. JPEG doesn't help when it comes to black and white diagrams.

Notes

Written on the 5th of January in 2016