Convert PDF to PNG fails with page number

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
timrprobocom
Posts: 1
Joined: 2018-12-03T17:10:23-07:00
Authentication code: 1152

Convert PDF to PNG fails with page number

Post by timrprobocom » 2018-12-03T17:17:25-07:00

ImageMagick 6.8.9-9 with GhostScript 9.26 on Ubuntu 16.04.5 LTS

I have a web page that converts the first page of submitted PDFs to a PNG using

Code: Select all

convert -density 300 p241504.pdf[0] -flatten -resize 640x +repage p241504.png
This has worked for years. Starting yesterday, I'm now getting:

Code: Select all

convert: FailedToExecuteCommand `"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-27596PshlNjRKAVT4%d" "-f/tmp/magick-27596m331V1WQSJUK" "-f/tmp/magick-27596RgwLE5h5aFVq"' (-1) @ error/delegate.c/ExternalDelegateCommand/461.
convert: no images defined `p241504.png' @ error/convert.c/ConvertImageCommand/3210.
If I omit the page number [0] from convert, it works correctly, although it ends up with the last page, which I don't want. If I run the "gs" command by itself, without the -f parameters, it works correctly. I've temporarily changed to calling "gs" directly, but I'd rather use the single command line. Anything changed recently?

Tim Roberts

User avatar
fmw42
Posts: 24095
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PDF to PNG fails with page number

Post by fmw42 » 2018-12-03T19:03:25-07:00

Did your Linux distro change/update recently. The date of the ImageMagick version is more important than the version, since they often do not change the release number when they patch.

If that happened, then there may be a new security patch that includes a modified policy.xml file. See https://stackoverflow.com/questions/528 ... 3#52863413 and https://imagemagick.org/script/resources.php

snibgo
Posts: 10929
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert PDF to PNG fails with page number

Post by snibgo » 2018-12-03T20:18:19-07:00

The OP says "If I omit the page number [0] from convert, it works correctly, although it ends up with the last page, which I don't want." So it is reading the PDF, and "-flatten" overwrites all the pages with the last one. So it's not a security problem.
snibgo's IM pages: im.snibgo.com

zineer
Posts: 1
Joined: 2018-12-05T22:06:42-07:00
Authentication code: 1152

Re: Convert PDF to PNG fails with page number

Post by zineer » 2018-12-05T22:26:14-07:00

I believe I'm hitting the same issue with a PDF to JPG conversion.

Code: Select all

$ convert '/tmp/test.pdf[0]'  '/tmp/test.jpg'
convert.im6: `%s' (%d) "gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-n4Brt84N--0000001" "-f/tmp/magick-G9ikuZ1i" "-f/tmp/magick-jnvNyXYN" @ error/utility.c/SystemCommand/1890.
convert.im6: Postscript delegate failed `/tmp/test.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/677.
convert.im6: no images defined `/tmp/test.jpg' @ error/convert.c/ConvertImageCommand/3044.
If I try without specifying the [0] it converts fine, creating a jpg for each of the 5 pages. I tried with the same PDF as I was last successful with (on November 21) and the same error occurs.

Looks like GhostScript was updated recently:

Code: Select all

$ convert -version
Version: ImageMagick 6.7.7-10 2018-09-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

$ gs -version
GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.

Post Reply