Error converting PDF

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
atani
Posts: 5
Joined: 2018-11-21T11:32:26-07:00
Authentication code: 1152

Error converting PDF

Post by atani » 2018-11-30T22:10:13-07:00

I'm running ubuntu 14.04 and have imagemagick 6.77 and ghostscript 9.26 installed and am trying to extract the first page of some PDFs to a JPEG, basically grabbing the first page as a JPG.

I've allowed "read" to the "delegate" domain for the various postscript file formats in policy.xml:

Code: Select all

    <policy domain="coder" rights="read" pattern="PS" />
    <policy domain="delegate" rights="read" pattern="PS" />
    <policy domain="coder" rights="read" pattern="PDF" />
    <policy domain="delegate" rights="read" pattern="PDF" />
    <policy domain="coder" rights="read" pattern="EPS" />
    <policy domain="coder" rights="read" pattern="XPS" />
    <policy domain="delegate" rights="read" pattern="EPS" />
    <policy domain="delegate" rights="read" pattern="XPS" />
It works fine for some but I've come across an error that I've not seen before in my limited experience with IM 6.77:

Code: Select all

convert /tmp/dfXvOyQHR0[0] -resample 72 /tmp/foo.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-0RtsLKdr--0000001" "-f/tmp/magick-RTEH2AAB" "-f/tmp/magick-tLKIPwXL" @ error/utility.c/SystemCommand/1890.
convert.im6: Postscript delegate failed `/tmp/dfXvOyQHR0': No such file or directory @ error/pdf.c/ReadPDFImage/677.
convert.im6: no images defined `/tmp/foo.jpg' @ error/convert.c/ConvertImageCommand/3044.
This kind of looks like it's saying there was an error running the ghostscript "gs" command, is that correct? If so is there anyway to tell the convert command to not remove what I'm assuming are the intermediate files that it is creating to feed to the "gs" command so I can try to debug it?

Or, even better, does anyone recognize what might be wrong here?

Many thanks!

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

Re: Error converting PDF

Post by fmw42 » 2018-11-30T23:29:49-07:00

Your IM 6.7.7 is ancient by version (about 350 versions old). What is the date of your version patch on ubuntu? Post what you get from

Code: Select all

convert -version
Linux does not often change the version number, but patches ImageMagick. Often they only patch for security issues and not bug fixes or enhancements or the patch is flawed. I cannot say what is happening here. Either you do not have Ghostscript installed where ImageMagick can find it or your version is flawed or Ghostscript is flawed or your security modifications did not take place or you modified them in the wrong location. Where did you update the policy.xml file? See https://imagemagick.org/script/resources.php for the locations and order in which they are checked.

Does

Code: Select all

convert -list configure | grep DELEGATES
list gslib?

If your command works for some PDF files and not other, then those PDF files may be corrupt or in some format that is not compatible with Ghostscript.

If the PDF files are CMYK, then you should add -colorspace sRGB (or RGB depending upon how old your version actually is) before reading the PDF file, especially if it has transparency in it. GS does not handle CMYKA files (with transparency).

GS 9.26 seems to be a new version. Does your command work with older versions of GS?

I am not sure of the use of -resample with PDF files.

Does this work?

Code: Select all

convert -density XX -colorspace sRGB image.pdf -density YY image.jpg
choose your density XX for the desired output file dimensions and your density YY for the dpi desired for the output.

atani
Posts: 5
Joined: 2018-11-21T11:32:26-07:00
Authentication code: 1152

Re: Error converting PDF

Post by atani » 2018-12-04T13:00:03-07:00

Yeah we have a really old system that we're trying to update step by step. I'm updating the /etc/ImageMagick/policy.xml and as I make changes I see them reflected in the output of identify -list policy.

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 

# convert -list configure | grep DELEGATES
DELEGATES     bzlib djvu fftw fontconfig freetype jbig jpeg jng jp2 lcms2 lqr lzma openexr pango png rsvg tiff x11 xml wmf zlib
So even though the ghostscript package is installed gslib doesn't appear in the list of delegates, which is strange since I can convert _some_ pdf files but not others and from the failure message it's clear that ImageMagick is aware of and using the "gs" command.

atani
Posts: 5
Joined: 2018-11-21T11:32:26-07:00
Authentication code: 1152

Re: Error converting PDF

Post by atani » 2018-12-04T13:00:59-07:00

And the

Code: Select all

convert -density XX -colorspace sRGB image.pdf -density YY image.jpg
comand options do work.

Post Reply