Broken PDF files : inconsistent error message ?

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
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Broken PDF files : inconsistent error message ?

Post by Xandros »

Hello !

I have searched for an answer to my issue on the forum but no avail, so here goes :

When loading a "broken" / malformed PDF file and trying to convert its first page to an image, I get the following (very common) error message :

Postscript delegate failed `blah.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/638

I'm using MagickWand's MagickReadImage function, but when I simply try the same thing with the commandline, I get the following :

Code: Select all

D:\>convert blah.pdf[0] test.jpg
warning: ignoring zlib error: incorrect data check
   **** Warning:  An error occurred while reading an XREF table.
   **** The file has been damaged.  This may have been caused
   **** by a problem while converting or transfering the file.
   **** Ghostscript will attempt to recover the data.
Error: /nocurrentpoint in --curveto--
Operand stack:
   --nostringval--   --dict:9/18(L)--   73.55   0   0   72.7   70.8   698.42
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval-
-   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   fa
lse   1   %stopped_push   1862   1   3   %oparray_pop   1861   1   3   %oparray_
pop   1845   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1
1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--
  --nostringval--   --nostringval--   %array_continue   --nostringval--   false
  1   %stopped_push   --nostringval--   %loop_continue
Dictionary stack:
   --dict:1158/1684(ro)(G)--   --dict:1/20(G)--   --dict:74/200(L)--   --dict:74
/200(L)--   --dict:106/127(ro)(G)--   --dict:278/300(ro)(G)--   --dict:24/25(L)-
-   --dict:4/6(L)--   --dict:21/40(L)--   --dict:1/1(ro)(G)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.64: Unrecoverable error, exit code 1
convert: `%s': %s "C:/Program Files/gs/gs8.64/bin/gswin32c.exe" -q -dQUIET -dPAR
ANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignT
oPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=
4 "-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=C:/DOCUME~1/ALEXAN~1.IST/LO
CALS~1/Temp/magick-VQ08axuz" "-fC:/DOCUME~1/ALEXAN~1.IST/LOCALS~1/Temp/magick-Gw
aQSEno" "-fC:/DOCUME~1/ALEXAN~1.IST/LOCALS~1/Temp/magick-6Feyqw9T" @ error/pdf.c
/InvokePDFDelegate/197.
convert: Postscript delegate failed `blah.pdf': No such f
ile or directory @ error/pdf.c/ReadPDFImage/638.
convert: missing an image filename `test.jpg' @ error/convert.c/ConvertImageComm
and/2919.
The question is : Would it be possible to return a more specific error message saying that the PDF file is broken/malformed ? I see that convert.exe outputs some text regarding the incorrect data check and so on, while the MagickReadImage fails and subsequent call to MagickGetException returns only the "no such file or directory", which is not true since the file is there !

Is there any other way to detect this maybe? any clues ?

Here is a link to the test file : http://fs.istratov.be/blah.pdf

Thanks !
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: Broken PDF files : inconsistent error message ?

Post by Xandros »

Any help pretty please ? :)
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: Broken PDF files : inconsistent error message ?

Post by Xandros »

Hi. Any chance to get an answer on this issue please ? with cherry on top ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Broken PDF files : inconsistent error message ?

Post by fmw42 »

I am not an expert on this, but it would appear you may have a problem with your ghostscript install. Try re-installing or upgrading ghostscript and then reinstall IM (or depending upon your platform, get a binary or RPM that has them both as part of the install).
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: Broken PDF files : inconsistent error message ?

Post by Xandros »

I tried that already, with different GS versions.

If you download the provided file and perform the same command, don't you have the same error message as me ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Broken PDF files : inconsistent error message ?

Post by fmw42 »

I tried downloading your file. But most of my tools won't even open it. So it appears to be either corrupt or malformed. One tool opened it as a totally white image. Even Adobe Reader says there is an error (117?) opening the file and cannot open it.

Try your command on a different pdf file, one you know is clean/good (i.e. opens in all the viewers).
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Broken PDF files : inconsistent error message ?

Post by anthony »

The error you were seeing is from ghostscript not from ImageMagick. And it is reporting that the file has a bad zlib compression table, and most likely corrupt. All the rest is devolving from that situation.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply