Ghostscript PDF -> TIFF conversion is awful for me

2019-03-08 21:37发布

My stomach churns when I see this kind of output.

http://www.freeimagehosting.net/uploads/e1097a5a10.jpg

and this was my command as suggested by Best way to convert pdf files to tiff files

gswin32c.exe -q -dNOPAUSE -sDEVICE=tiffg4 -sOutputFile=a.tif a.pdf -c quit

What am I doing wrong?

(commercial products will not be considered)

7条回答
Anthone
2楼-- · 2019-03-08 22:25

I have been using ImageMagick for quite a sometime. It's very nice tool with a lot of features.

Install ImageMagick and run following command. This is what I used on Linux, you may have to replace convert with the correct one.

Below command converts PDFs to CCITT Group 3 standard TIFs (Fax standard):

convert -define quantum:polarity=min-is-white \
        -endian MSB \
        -units PixelsPerInch \
        -density 204x196 \
        -monochrome \
        -compress Fax \
        -sample 1728 \
        "input.pdf" "output.tif"

Also you may use GraphicsMagick, it is also similar to ImageMagick, but ImageMagick more concerns with quality than speed.

查看更多
Evening l夕情丶
3楼-- · 2019-03-08 22:30

tiffg4 is a black&white output device. You should use tiff24nc or tiff12nc as the output device colour PDFs - see ghostscript output devices. These will be uncompressed but you could put the resulting TIFFs through imagemagick or similar to resave as compressed TIFF.

查看更多
霸刀☆藐视天下
4楼-- · 2019-03-08 22:32

setori's command does not specify the resolution to use for the tiffg4 output. The consequence is: Ghostscript will use its default setting for that output, which is 204x196dpi.

In order to increase the resolution to 600dpi, add a -r600 commandline parameter:

gswin32c.exe ^
   -o output.tiff ^
   -sDEVICE=tiffg4 ^
   -r600 ^
    input.pdf

Also note that TIFFG4 is the standard fax format and as such it uses black+white/grayscale only, but no colors.

@jeff: Have you ever tried the -dDITHERPPI=<lpi> parameter with Ghostscript? (Reasonable values for lpi are N/5 to N/20, where N is the resolution in dpi. So for -r600 use try with -dDITHERPPI=30 to dDITHERPPI=120).

查看更多
欢心
5楼-- · 2019-03-08 22:32

I ran into the same problem with fax pages.

I was using Imagick in php and this command fixed the way it looked.

$Imagick->blackThresholdImage('grey');

I didn't see any threshold option using 'gs' but convert may also work for you.

convert a.pdf -threshold 60% a.tif
查看更多
家丑人穷心不美
6楼-- · 2019-03-08 22:35

Like other posts suggested, use a color format (e.g. -sDEVICE=tiff24nc) and specify a higher resolution (e.g. -r600x600):

gswin32c.exe -q -dNOPAUSE -r600 -sDEVICE=tiff24nc -sOutputFile=a.tif a.pdf -c quit
查看更多
太酷不给撩
7楼-- · 2019-03-08 22:36

Thanks guys this is what I ended up with

     os.popen(' '.join([
                       self._ghostscriptPath + 'gswin32c.exe', 
                       '-q',
                       '-dNOPAUSE',
                       '-dBATCH',
                       '-r800',
                       '-sDEVICE=tiffg4',
                       '-sPAPERSIZE=a4',
                       '-sOutputFile=%s %s' % (tifDest, pdfSource),
                       ]))
查看更多
登录 后发表回答