convert 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?".
Post Reply
ayahuasca

convert pdf to jpg

Post by ayahuasca »

Hello,

i am trying to convert pdf files (or 1 page of a pdf file) to jpg to make a previeuw of the pdf availeble.

I am doing this with ImageMagick and Ghostscript.

When i do this in a cmd on my windows server it works perfectly.
When i try to do it in a php file it does not do anything.

the command i am using is this:
<?
exec("convert 1.pdf[0] 1.jpg");
?>

could somebody please tel me what i am doing wrong?
Last edited by ayahuasca on 2007-02-06T08:51:06-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert pdf to jpg

Post by Bonzo »

I have not used pdf but as far as I can tell you are trying to convert layer 0 to a jpg ?
Have you tried:

Code: Select all

exec("convert '1.pdf[0]' 1.jpg");
ayahuasca

Re: convert pdf to jpg

Post by ayahuasca »

Yes i have tried it, doesn't work.

What i am doing is convert page 1 of the pdf to jpg.

I am wondering if exec() does work. Is there mayby a simpel command to check if exec does anything?
ayahuasca

Re: convert pdf to jpg

Post by ayahuasca »

Problem solved.

The big secret is to restart your server after completing the installation script of ImageMagick and Ghostscript!

Anywayz, Thanks for trying...
ridera

Re: convert pdf to jpg

Post by ridera »

I'm working on the same thing, trying to get a thumbnail of the first page to show. I'm posting another topic especially for it.

However, as to your problem: add "-debug exception" to your command; it'll show you what's going on. A typical command, with debug looks like this:

$command= "/usr/local/bin/convert -debug exception $precomm $fpfile $comm $tb_fpfile";

exec($command, $convert_array, $code); Note the $convert_array; that's where your debug message is

My guess is that path to "convert" is not correct.
pieter

Re: convert pdf to jpg

Post by pieter »

I had the same problem. I solved it by replacing the exec() command by the popen() function. Maybe this will be your solution as wel.. Good luck!
Post Reply