allinonemovie
allinonemovie

Reputation: 734

ImageMagick generates corrupted PDF file

When I try to convert an image to PDF using ImageMagick by executing the command

mogrify -format pdf ImageMagick.png

the resulting PDF is corrupted. When I try to open it using MuPDF it fails:

error: cannot recognize version marker
warning: trying to repair broken xref
warning: repairing PDF document
error: name too long
warning: skipping ahead to next token
error: invalid key in dict
error: invalid key in dict
error: name too long
warning: skipping ahead to next token
error: no objects found
mupdf: error: cannot open document

The output of ImageMagick using the -verbose-flag is:

ImageMagick.png PNG 600x621 600x621+0+0 8-bit sRGB 123261B 0.020u 0:00.009
ImageMagick.png=>ImageMagick.pdf PNG 600x621 600x621+0+0 8-bit sRGB 122974B 0.070u 0:00.060

The problem with the PDF file seems to be, that the first bytes of the file aren't %PDF-.

This is my input-file input-file

And this is the resulting PDF

My system:

Upvotes: 1

Views: 1328

Answers (2)

allinonemovie
allinonemovie

Reputation: 734

The problem was, that ghostscript wasn't installed. ImageMagick doesn't seem to throw an error when ghostscript isn't installed.

To install ghostscript use pacman -S ghostscript

Upvotes: 2

emcconville
emcconville

Reputation: 24439

Your command is just rewriting a PNG over itself. I don't know how the ImageMagick.pdf file was generated, but it really is just a PNG image with a PDF filename. Try one of the following...

convert ImageMagick.png ImageMagick.pdf

... or ...

mogrify -format PDF -path ./ ImageMagick.png

Upvotes: 0

Related Questions