PDF to PNG converts only first page if colorspace=sRGB is se

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mdok
Posts: 2
Joined: 2013-01-16T18:14:08-07:00
Authentication code: 6789

PDF to PNG converts only first page if colorspace=sRGB is se

Post by mdok »

In order to convert a PDF with 100 pages to single PNG files, I've been using the following command:

Code: Select all

C:\Program files\ImageMagick\convert -density 150 -alpha Opaque file.pdf file.png
But that resulted in PNGs that were over-saturated. This is why I modified the command to the following one, adding the `colorspace` parameter:

Code: Select all

C:\Program files\ImageMagick\convert -colorspace sRGB -density 150 -alpha Opaque file.pdf file.png
The colors look good now. However, only the first page of the PDF is converted now, all others are just dropped. Why? Is the order of the arguments wrong? I've tested different orders but none with success.

However, accessing the subsequent pages directly (via file.pdf[1] etc.) works. But why doesn't it convert the full document in batch anymore?

ImageMagick version info:

Code: Select all

Version: ImageMagick 6.8.1-9 2013-01-04 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: OpenMP
Delegates: bzlib freetype jp2 jpeg lcms lzma ps tiff x xml zlib
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to PNG converts only first page if colorspace=sRGB i

Post by fmw42 »

I believe the order is correct. All these arguments need to be put ahead of the reading of the input.pdf file.

try

C:\Program files\ImageMagick\convert -colorspace sRGB -density 150 -alpha off file.pdf file.png

The problem is that IM relies upon Ghostscript. Ghostscript can only process either single page with transparency or multiple pages that have no transparency in pdf files.

To handle multiple pages, there must be no transparency and the delegates.xml file must use sDEVICE=pnmraw rather than pngalpha. You need to check your delegates.xml file and look at the line:

<delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>

At least that is what is done on unix systems. I have no real experience with Windows regarding this.
mdok
Posts: 2
Joined: 2013-01-16T18:14:08-07:00
Authentication code: 6789

Re: PDF to PNG converts only first page if colorspace=sRGB i

Post by mdok »

Wow, this works perfectly :) Thank you so much!
Post Reply