Ghostscript: how to decide the output resolution o

2020-07-13 09:23发布

问题:

I need to extract TIFF images from a bunch of multi-page PDF files from a scanner. During the scanning I specified a resolution of 600dpi.

  1. Here is the code I used to generate TIFF images:

    gs -q -dNOPAUSE -sDEVICE=tiffg4 \
       -sOutputFile=a_page%02d.tif a.pdf -r600x600 -c quit
    

    This gave me the correct number of TIFF images, however, the image dimension is smaller than I expected.

    No matter how I change the -r option, the output images have the same size.

    What happened here?

  2. The output TIFF images have some compression, how should I change the gs option so that they do NOT contain any compression?

    http://pages.cs.wisc.edu/~ghost/doc/cvs/Devices.htm#TIFF has a few options to select, but seems to me no one means "8-bit Black&White" + "Compression Free".

Does anybody how to solve these two problems?

回答1:

If you use tiffg4 for output, then you implicitely asked to also get the Fax G4 compression type in the PDF.

You can tell Ghostscript to use no compression by using a different TIFF output device, such as tiffgray (gray, 8bit), tiff24nc (RGB-TIFF, 8bit for each color channel), tiff32nc (CMYK-TIFF, 8bit for each color channel), .... All these output types are uncompressed by default.

You can also use tiffg4 but remove the compression:

gs \
 -o a_page%02d.tif \
 -sDEVICE=tiffg4 \
 -r600x600 \
 -g4960x7020 \
 -sCompression=none \
  a.pdf

BTW, there is no such thing as "8bit Black+White". There is "1bit Black+White", but as soon as you go beyond 1bit, you'll enter the realm of grayscales... :-)



回答2:

Try this:

 gs \
  -o a_page%02d.tif \
  -sDEVICE=tiffg4 \
  -r600x600 \
  -g4960x7020 \
   a.pdf

-g is for specifying the absolute number of pixels used by the TIFF in each dimension. That much for getting the correct resolution/dimension.