Simple Ghostscript Commands (PDF to TIFF or JPEG)

Below are quick examples of Ghostscript commands (these are the ones used in my previously posted scripts, but in a form that is closer to what would be typed to run from the command line, rather than in a bash script). I’ve found using Ghostscript directly to work with PDFs is far faster and uses less memory than ImageMagick.

Example 1 (color LZW TIFF files):

gs -sDEVICE=tiff24nc -sCompression=lzw -r300x300  -dNOPAUSE -sOutputFile="path\to\output\filename%04d.tif" inputfile.pdf

In the above -sDEVICE sets the file format to full color (24 bpp) TIFF, -sCompression sets lzw compression (LZW has been off-patent long enough for pretty much universal support, and makes the files a manageable size), -r is the resolution, for color images 300×300 is generally high enough, -sNOPAUSE keeps Ghostscript running between pages, and -sOutputFile sets the destination file. The %04d in the output file is replaced by 4 digit (leading 0′s) page numbers.

Also, available for smaller files, if the format is acceptable, is to set -sDEVICE to png16m, this is for 24 bpp (16 million color) PNG files (make sure the output file ends in .png too). When making PNG files, eliminate the -Compression option.

There is no built in device in Ghostscript to make LZW color TIFF files (the tifflzw device is monochrome), but tiff24nc supports the -Compression option.

Example 2 (monochrome group 4 TIFF files):

gs -sDEVICE=tiffg4 -dNOPAUSE -r600x600 -sOutputFile="path\to\output\filename%04d.tif" inputfile.pdf

The above script does the same, but using group 4 monochrome compression (the tiffg4 device has compression built in), additionally it uses 600×600 resolution, which is what I like to use for monochrome (it allows for better dithering of gray, and all of the small details in spreadsheets to be readable).

Example 3 (color JPEG files):

gs -sDEVICE=jpeg -dNOPAUSE -r300x300 -sOutputFile="path\to\output\filename%04d.tif" inputfile.jpg

Using JPEG compression above creates far smaller files than (color) TIFF or PNG, but loses quality, this quality loss can be very obvious in areas of high contrast, such as text or line drawings.

2 thoughts on “Simple Ghostscript Commands (PDF to TIFF or JPEG)

  1. I was looking for a way to increase the line weight or contrast in a g4 TIF file created from a PostScript printer capture file out of a CAD system. Maybe I need to look at the printer or CAD settings?

    • It’s been a while since I’ve printed from any CAD software, but from what I remember in Auto CAD there was something along the lines of “pen settings” I believe. There were some pre-defined styles, or you could manually set the thickness/color of each line if you chose (so that you could make all the default red, yellow, and blue ones come out as black instead).

      Once a file is in true B&W color space (no grays) it is very hard to manipulate. I believe Auto CAD still uses the “pen” terminology for this, so that may help you find what you’re looking for, once you get the correct dialogue box it’s pretty strait forward, hope this helps, it’s been years since I’ve needed to deal with that issue, and I’ve only ever used Auto CAD.

Leave a Reply to drake Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>