PDF to JPG fails for some files

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
phy9pas

PDF to JPG fails for some files

Post by phy9pas »

Hello,

I'm trying to convert PDF files to JPG using the comand line call in PHP

here's my code:

Code: Select all

<?php

$dir = "/var/www/vhosts/domain/httpdocs/resources/";

if (!isset($_GET['file'])) { echo('no file seleected'); exit(); }
$file = $_GET['file'];
$path_parts = pathinfo($dir.$file);

echo $path_parts['dirname'], "<br/>";
echo $path_parts['basename'], "<br/>";
echo $path_parts['extension'], "<br/>";
echo $path_parts['filename'], "<br/>";

$command = '"/usr/bin/convert" "' . $dir .$file.'[0]" "' . $dir. $path_parts['filename'].'.jpg"';

echo $command . "<br /><br />";
	
$result = system($command, $retval);
if ($result==-1) { echo("fail<br /><br />"); }
echo("result:$result<br/><br/>");
echo("returnval:$retval<br/><br/>");

?>
For some pdf files this works fine and extracts page 1 of the PDF and saves it as a jpg.
For otehr files it fails.

Here are two example files, one works and one doesn't

http://previewyoursite.co.uk/temp/works.pdf

http://previewyoursite.co.uk/temp/notworks.pdf

I have several examples of files that work and ones that don't but I can't see a common difference between the two.

Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PDF to JPG fails for some files

Post by magick »

Both files converted for us without complaint. We're using ImageMagick 6.5.8-10 and Ghostscript 8.70.
may191

Re: PDF to JPG fails for some files

Post by may191 »

I am having the exact same issue.

What Host are you using Phy9Pass?

I am on a godaddy, shared linux host. They give you a ImageMagick url

Code: Select all

'/usr/local/bin/convert -version'
Outputs: Version: ImageMagick 6.2.8

My scripts to convert PDF to JPG work only from time to time aswell. I think my Issue could be that, Ghostscript is not installed. I have herd some people have run into more complex image transformations failing without it. But basics still working.

Is there something in some PDF's that is trying to use ghostscript, and in some its not needed?

How can I test to see if ghostscript is installed.

Can gostscript be installed on shared hosting platform like godaddy.?

Thanks, lovin ImageMagick so far.

Ryan.
Post Reply