Gavin R. Putland,  BE PhD

Saturday, August 16, 2014 (Comment)

How to convert a PostScript file to PDF, embed all fonts, embed substitutes for missing fonts, convert colors to grayscale, prevent lossy compression of images, and preserve image resolution

Invoke Ghostscript using the following command (on one line, with no spaces after the hyphens):

ps2pdf -dPDFSETTINGS=/prepress -dPDFUseOldCMS=false -dProcessColorModel=/DeviceGray -dColorConversionStrategy=/Gray -dAutoFilterGrayImages=false -dAutoFilterColorImages=false -dGrayImageFilter=/FlateEncode -dColorImageFilter=/FlateEncode -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false input.ps output.pdf

Notes on the switches:

-dPDFSETTINGS=/prepress causes embedding of fonts, including reasonable substitutions for unavailable fonts. Alternative switches for embedding fonts do not include substitution.

-dPDFUseOldCMS=false forces the use of new code. The old code may fail to convert fully to grayscale.

-dProcessColorModel=/DeviceGray -dColorConversionStrategy=/Gray are the usual switches for converting text and images, respectively, to grayscale. The latter requires the former. To preserve colors, you would omit these switches or set them differently. (P.S.: If some images turn partly or fully black, or negative, try omitting the latter switch. If this causes the appearance of unacceptable color, the affected images will need to be converted to grayscale by some other means.)

-dAutoFilterGrayImages=false -dAutoFilterColorImages=false -dGrayImageFilter=/FlateEncode -dColorImageFilter=/FlateEncode prevent JPEG (lossy) compression of images.

-dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false prevent changes in resolution of images. Without these switches, the /prepress setting will give an image resolution of 1200dpi for mono and only 300dpi for grayscale and color. Changes in resolution not only degrade the images, but also take time and memory; on large documents with many images, they may even cause Ghostscript to run out of memory, in which case it aborts with a “segmentation fault” message.

Indeed, it was a segmentation fault that forced me to look into these matters. Using /default instead of /prepress avoided the segfault and apparently suppressed downsampling of images, but unfortunately also disabled font substitution. Using /prepress with the last three switches was a complete solution.


[Last modified August 19, 2014.]


Creative Commons License         Return to Contents
comments powered by Disqus