Issue converting PDF to JPG

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?".
squiddon

Issue converting PDF to JPG

Post by squiddon »

Hi guys,

I'm a bit of a n00b to ImageMagick and I'm having trouble converting a PDF document to a JPG. The conversion seems to work on initial inspection but the output file is an unreadable JPG file. I'm running ImageMagick and GhostScript on a linux server. Has anyone had a similar issue?

Cheers in advance!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issue converting PDF to JPG

Post by Bonzo »

Supply some more info:
Imagemagick version
How are you working - command line, php etc.
Example input image if possible.
Example of output if possible.
squiddon

Re: Issue converting PDF to JPG

Post by squiddon »

ImageMagick-6.5.2-7

Currently working command line but the intention is to exec it in a PHP script.

PM'ed input and output.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue converting PDF to JPG

Post by fmw42 »

I have had that problem I believe. I think it is due to the pdf being cmyk format and my ghostscript cannot handle that. To get around that, if that is the problem, try

convert -colorspace rgb image.pdf image.jpg
squiddon

Re: Issue converting PDF to JPG

Post by squiddon »

Thanks for the suggestion, I had a go but to no avail. I've tried to change the document in case it is also a document permissions issue (I had to try!), but again, no joy.

Strange thing is that the convert creates an image file of what looks to be correct filesize. :?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issue converting PDF to JPG

Post by Bonzo »

I think there is a problem with your input pdf; I have tried different things including Freds suggestion but get this error everytime using php. I didn't even get the output you did !
Array
(
[0] => convert: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=C:/Users/Anthony/AppData/Local/Temp/magick-wlRI0-Rd" "-fC:/Users/Anthony/AppData/Local/Temp/magick-dkn1da4r" "-fC:/Users/Anthony/AppData/Local/Temp/magick-g9EoQYAV" @ utility.c/SystemCommand/1843.
[1] => convert: Postscript delegate failed `test.pdf': No such file or directory @ pdf.c/ReadPDFImage/612.
[2] => convert: missing an image filename `image.jpg' @ convert.c/ConvertImageCommand/2775.
)
1
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue converting PDF to JPG

Post by fmw42 »

can you post your pdf?
squiddon

Re: Issue converting PDF to JPG

Post by squiddon »

I'll find one that I'm generating using FPDF, which will ultimately be my input, bear with me a second...
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issue converting PDF to JPG

Post by Bonzo »

I have just created a pdf using Microsoft office 2007 and I get the same results. How did you create your pdf ?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issue converting PDF to JPG

Post by Bonzo »

404 Error with that link :(
squiddon

Re: Issue converting PDF to JPG

Post by squiddon »

Should be okay now, otherwise is there a way of attaching the doc to the board?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issue converting PDF to JPG

Post by Bonzo »

WOOPS New PC and I do not think I have installed Ghost script :?

Back in a 1/2hr or so - Dinner ready.

The link works now.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Issue converting PDF to JPG

Post by Bonzo »

Very sorry for the false leads - installed Ghostscript now and it all works OK on the posted sample.

IM version 6.5.1

What result do you get for your posted pdf ?

Code: Select all

<?php

exec("convert test.pdf jpg4.jpg"); 
exec("convert -density 300 test.pdf jpg5.jpg");

?>
<img src="jpg4.jpg">
<img src="jpg5.jpg">
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue converting PDF to JPG

Post by fmw42 »


This works just fine for me on IM 6.5.2-7 Q16 Mac OSX Tiger with Ghostscript ghostscript-8.61.tar.gz

convert test.pdf test.jpg
Image



convert -list configure

Path: /usr/local/lib/ImageMagick-6.5.2/config/configure.xml

Name Value
-------------------------------------------------------------------------------
CC gcc -std=gnu99
CFLAGS -I/usr/local/include/lqr-1 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -g -O2 -Wall -W -D_THREAD_SAFE
CONFIGURE ./configure '--enable-delegate-build' '--enable-shared' '--disable-static' '--with-modules' '--with-quantum-depth=16' '--with-gslib' '--without-wmf' '--enable-libtool-verbose' '--disable-dependency-tracking' '--with-gs-font-dir=/usr/local/share/ghostscript/fonts/' '--with-lqr'
COPYRIGHT Copyright (C) 1999-2009 ImageMagick Studio LLC
CPPFLAGS -I/usr/local/include/ImageMagick
CXX g++
CXXFLAGS -g -O2 -Wall -W -D_THREAD_SAFE
DEFS -DHAVE_CONFIG_H
DELEGATES bzlib fontconfig freetype gs jpeg jng jp2 lcms lqr openexr png tiff x11 xml zlib
Post Reply