简体   繁体   中英

shrinking a PDF

I'm not sure if this is the right place to post this question.

I'm trying to reduce the size of multiple 7MB PDF files so I tried this ghostscript commands I found online:

simple ghostscript with printer quality setting
    gswin32c.exe -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

tried this
    gswin32c.exe -o output.pdf -sDEVICE=pdfwrite -dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode input.pdf

and this
    gswin32c.exe -o output.pdf -sDEVICE=pdfwrite -dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false input.pdf

but in all cases the PDF files obtained were 'bigger' that the original. All these pdf files are basically a collection of scanned images so maybe I need a specific option to 'tell' ghostscript to compress them ?

The strange thing I found is that using the trial version of phantom pdf I was able to reduce the size to 2-5MB without visible loss of quality.

How do I do the same with ghostscript ?

Firstly, Ghostscript (or more accurately, Ghostscript's pdfwrite device) doesn't 'shrink' PDF files, it makes new ones which may, or may not, be smaller.

Secondly, its practically impossible to say what might be happening with a PDF file without an example to look at.

If your files really are scanned images, then (assuming sensible initial compression) there's probably no way to reduce the file size without reducing quality. You might not notice the reduction in quality, especilaly if you're just viewing on screen, but it will be there.

Random poking with command lines which you run across online is probably not going to result in useful output either; you really need to understand where the size is being used in your original files, and then select options which are likely to reduce that.

For example, you say the pages are scanned images; there are only two realistic ways to reduce the size of an image, downsample it to a lower resolution, or select a different (more efficient, possibly lossy, compression). Ghostscript already compresses image data (unless you tell it not to).

The latter two of your command lines explicitly disable image downsampling, so they are not likely to reduce the size of scanned images. (by default the pdfwrite device doesn't downsample images, we try to preserve quality)

The middle option disables auto compression, and selects Flate compression. If your images were previously JPEG compressed, or are not contone images, then this is probably reasonable.

You also say that the PDF files got larger, most likely this is due to using compressed object streams and xref, which is a PDF 1.5 feature that the pdfwrite device doesn't support. However its not likely to save you much space.

I'd say the most likely difference is that 'phantom PDF' is using more aggressive downsampling, which you could reproduce with pdfwrite.

I'm assuming, of course, that you are using a recent version of Ghostscript. Older versions unsurprisingly perform less well than recent ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM