Page 1 of 1
convert pdf to pdf produces huge pdf
Posted: 2017-11-15T12:17:24-07:00
by jauson
I'm trying to fatten a pdf and have good quality. My command is:
Code: Select all
convert -density 288 input.pdf output.pdf
My pdf of 5 megs becomes 130 megs. It's 6 pages, but they are full of color and images.
If I run this GS command on it, it shrinks it down to 930k.
Code: Select all
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=/LeaveColorUnchanged \
-dAutoFilterColorImages=true \
-dAutoFilterGrayImages=true \
-dDownsampleMonoImages=true \
-dDownsampleGrayImages=true \
-dDownsampleColorImages=true \
-sOutputFile=document_flat.pdf document_original.pdf
Can I achieve this with the single convert command above?
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T12:24:01-07:00
by fmw42
ImageMagick is a raster processor, not a vector to vector processor. So if you have a vector PDF and you convert it to PDF using ImageMagick, it will rasterize the PDF to pixels (not vectors) and imbed the raster image in a vector PDF shell. That will make the output much larger than the input. So if you want to go vector to vector, then you should use some other tool.
You might be able to achieve a similar result to using Ghostscript.
1) try adding -compress JPG -quality 80 ( or whatever quality you want for the jpg). I do not know if this will work.
2) modify your delegates.xml file to use the same arguments for gs in the appropriate line
Sorry, I am not an expert on either suggestion.
Perhaps if you post your input PDF, we can test with it.
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T12:45:24-07:00
by jauson
convert TestThis.pdf -compress JPG -quality 80 TestThis-converted.pdf
convert.exe: unrecognized image compression `JPG' @ error/convert.c/ConvertImageCommand/1119.
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T12:49:05-07:00
by fmw42
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T12:57:01-07:00
by jauson
convert TestThis.pdf -compress JPEG -quality 80 TestThis-converted.pdf
JPEG works, but it made the file even bigger
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T12:59:02-07:00
by fmw42
Lower the quality value is all I can suggest. Sorry, I am not an expert on PDF files.
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T13:11:35-07:00
by snibgo
jauson wrote:My pdf of 5 megs becomes 130 megs. It's 6 pages, but they are full of color and images.
If I run this GS command on it, it shrinks it down to 930k.
...
Can I achieve this with the single convert command above?
Without seeing your PDF file, we can only offer general guidance.
Converting vector to raster almost always increases the filesize.
If your PDF has vector data and you want to reduce the size while keeping quality, IM is not the right tool.
If your PDF has only raster data, IM
might be able to reduce the filesize.
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T15:38:08-07:00
by jauson
I'm trying to do this in a single command using pipes, but I'm not sure if its setting the format properly. After this command, i use another program to process this pdf and it says unsupported image type. it's a java program, throwing this error:
Code: Select all
Caused by: javax.imageio.IIOException: Unsupported Image Type
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1068)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1039)
Code: Select all
convert -density 288 input.pdf - | gswin64c \
-dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=/LeaveColorUnchanged \
-dAutoFilterColorImages=true \
-dAutoFilterGrayImages=true \
-dDownsampleMonoImages=true \
-dDownsampleGrayImages=true \
-dDownsampleColorImages=true \
-sOutputFile=converted_flattened.pdf -
I tried adding
and
doesn't seem to fix it.
I think its a GS issue.
Re: convert pdf to pdf produces huge pdf
Posted: 2017-11-15T16:20:26-07:00
by fmw42
I do not see any point to piping from ImageMagick to Ghostscript to do further processing. If you want to change the density use
gs -rXRESxYRES
in Ghostscript.
Or add all your gs arguments to the delegates.xml file in ImageMagick for PS or PDF (wherever the sDEVICE=gs