Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to downsample images within PDF file?

Need a Java-based solution or, at the worst, command-line for Linux.

I tried to use Ghostscript:

gs -sDEVICE=pdfwrite -dPDFA -dBATCH -dNOPAUSE -dUseCIEColor \    -sProcessColorModel=DeviceCMYK -sPDFACompatibilityPolicy=1 \    -sOutputFile=downgraded.pdf leon_range_my12_w22_brochure.pdf 

but I got a lot of errors...

like image 413
macromaniac Avatar asked Feb 29 '12 10:02

macromaniac


People also ask

How do I downsample an image mask in Acrobat?

1 Correct answerGo to File> Save as other> Optimized PDF> Go to Discard Objects, Discard User Data and Clean Up, open each section and check everything on. If your PDF is still too big, you can increase downsampling until you get the desired final size.


2 Answers

Here's an example of how you can downsample all (color, gray and mono) images to 72dpi with a Ghostscript commandline:

gs \   -o downsampled.pdf \   -sDEVICE=pdfwrite \   -dDownsampleColorImages=true \   -dDownsampleGrayImages=true \   -dDownsampleMonoImages=true \   -dColorImageResolution=72 \   -dGrayImageResolution=72 \   -dMonoImageResolution=72 \   -dColorImageDownsampleThreshold=1.0 \   -dGrayImageDownsampleThreshold=1.0 \   -dMonoImageDownsampleThreshold=1.0 \    input.pdf 

Update:
The *ImageDownsampleThreshold=1.0 parameters enforce that all Images with a resolution higher than the target resolution of 72 dpi will be downsampled. If this parameter is not given (or set to a different value), the default values will be used: *ImageDownsampleThreshold=1.5. This default value will only downsample images with a value of 108 dpi (or higher) and leave the other ones untouched.

like image 185
Kurt Pfeifle Avatar answered Oct 01 '22 11:10

Kurt Pfeifle


This is what I am using:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=OUTPUT.pdf INPUT.pdf

For your reference:

-dPDFSETTINGS=/screen (screen-view-only quality, 72 dpi images)

-dPDFSETTINGS=/ebook (low quality, 150 dpi images)

-dPDFSETTINGS=/printer (high quality, 300 dpi images)

-dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)

-dPDFSETTINGS=/default (almost identical to /screen)

like image 28
Roger Avatar answered Oct 01 '22 10:10

Roger