Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ghostscript pdfwrite specify jpeg quality

I'm trying to concatenate multiple pdf files which basically are the pages of a photobook containing jpg images. For my output pdf file I wish to adjust the image resolution to 300 dpi and I want to keep the best quality. The commands I'm using are:

gswin64c.exe -dNOPAUSE -dBATCH ^-dDownsampleColorImages=true -dColorImageResolution=300 ^-dDownsampleGrayImages=true -dGrayImageResolution=300 ^-dDownsampleMonoImages=true -dMonoImageResolution=300 ^-sDEVICE=pdfwrite -dJPEGQ=100 -sOutputFile=out.pdf in1.pdf in2.pdf

However, it seems that -dJPEGQ=100 has no effect on the output. Changing this parameter leads to the same filesize and artifacts are visible in the images for all values. Running the command with the option -dPDFSETTINGS=/printer I get better results without artifacts, however this option should also result in 300 dpi. So what is the correct command to specify the quality of the jpg images in the output file?

like image 615
tribol Avatar asked Nov 28 '16 16:11

tribol


1 Answers

The solution is adjusting the DCTEncode filter with follwing commands:

gswin64c.exe -sOutputFile=out.pdf -dNOPAUSE -dBATCH ^-sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -c "<< /ColorACSImageDict << /VSamples [ 1 1 1 1 ] /HSamples [ 1 1 1 1 ] /QFactor 0.08 /Blend 1 >> /ColorImageDownsampleType /Bicubic /ColorConversionStrategy /LeaveColorUnchanged >> setdistillerparams" -f in1.pdf

which lead to a compressed file with satisfactory quality for me and can be adjusted to each individual needs.

Edit:

the .setpdfwrite argument is deprecated for recent ghostscript releases (> 9.50), so I removed it in the answer

like image 67
tribol Avatar answered Sep 28 '22 13:09

tribol