Page 1 of 1

PDF to JPG fails for some files

Posted: 2010-01-07T09:03:32-07:00
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

Re: PDF to JPG fails for some files

Posted: 2010-01-07T10:49:39-07:00
by magick
Both files converted for us without complaint. We're using ImageMagick 6.5.8-10 and Ghostscript 8.70.

Re: PDF to JPG fails for some files

Posted: 2010-02-04T00:35:17-07:00
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.