ImageMagick: PDF color profile conversion creates giant PDF file?

I use the following command:

convert sourcefile.pdf -profile "cmyk.icc" -profile "srgb.icc" +profile "*" output.pdf 

In the test 3 MB file, it creates 20 MB PDF, which is terrible quality.

If I add the -density 600 option, the file explodes to over 600 mb. Is there a way to convert the color space while keeping everything else? This is a temporary PDF file for further processing, so I do not need it exactly the same size, but I can not deal with the gigantic sizes of PDF files.

+4
source share
1 answer

Your problem is not using color profiles with convert and ImageMagick.

I guarantee that you will have the same problem with these commands:

 convert sourcefile.pdf output.pdf convert -density 600 sourcefile.pdf output.pdf 

Your real problem is using ImageMagick for a task in which it is bad. Since ImageMagick cannot work with PDF files. It can only work with bitmap images. Here he excels and where he is really really good.

Since PDF files are not bitmaps (although they may contain them), ImageMagick uses a delegate to convert PDF pages to single full-page images. This delegate is ghostscript.

Only after receiving the delegation result (bitmap) does ImageMagick start working on your profile changes. After that, he converts the image back to PDF - but now the PDF has lost all the old vector objects, and only a pixelated version is left from each page.

Just as you cannot return the meat in one piece, as soon as you chop it through a meat grinder - you cannot return the original PDF objects (vector images, fonts, etc.) as soon as you "Rasterized its pages, such like ImageMagick. "


Solution for your problem (messing with color profiles, used PDF files) :. Use the right tool for the job. Learn to use Ghostscript directly ! (Because Ghostscript can embed ICC color profiles in PDF files without changing pages in bitmaps first. You don't need ImageMagick for this!)

+1
source

Source: https://habr.com/ru/post/1435390/


All Articles