I want to convert all pages of a PDF to JPEG. The PHP-script does what it should locally but fails on our live server.
$pdf = Zend_Pdf::load($file['tmp_name']);
echo 'Pages: '.sizeof($pdf->pages).'<br />';
for($pageCounter = 0; $pageCounter < $object->getNumberOfPages(); $pageCounter++) {
$pagenumber = $pageCounter + 1;
$currentfilename = $filename . "_$pagenumber.jpg";
echo $thumbPath.$currentfilename.'<br />';
echo $file['tmp_name']."[$pageCounter]<br />";
$return; $out;
exec("convert -density 250 '".$file['tmp_name']."[$pageCounter]' -quality 60 '$bigPath$currentfilename'", $out, $return);
var_dump($return); echo '<br />'; echo var_dump($out); echo '<br />';
exec("/usr/bin/convert -density 16 '/home/data/websites/www/meonline.be/public_html/images/magazines/".$file['name']."[$pageCounter]' -quality 60 '$thumbPath$currentfilename'", $out, $return);
var_dump($return); echo '<br />';
}
I tried to refer to the convert command by explicitly pointing to /usr/bin/convert & /usr/local/bin/convert. I always get 1 (or 127 if i'm pointing to the wrong folder) and the output array is always empty. All folder as shown exist and have mode 777 set.
Here's a summary of all echoed output:
Full exec command:
convert -density 250 '/home/data/websites/www/meonline.be/public_html/images/magazines/HogeschoolPromotorenP-studenten.pdf[0]' -quality 60 '/home/data/websites/www/meonline.be/public_html/images/magazines/big/pLjB9_HogeschoolPromotorenP-studenten.pdf/hogeschoolpromotorenp-studenten_1399449783_1.jpg'
First echo echo 'Pages: '.sizeof($pdf->pages).'<br />';
pages: 1
Second echo echo $thumbPath.$currentfilename.'<br />';
/home/data/websites/www/meonline.be/public_html/images/magazines/thumb/pLjB9_HogeschoolPromotorenP-studenten.pdf/hogeschoolpromotorenp-studenten_1399449783_1.jpg
Third echo echo $file['tmp_name']."[$pageCounter]<br />";
/home/data/websites/www/meonline.be/public_html/images/magazines/HogeschoolPromotorenP-studenten.pdf[0]
Fourth echo var_dump($return); echo '<br />'; echo var_dump($out); echo '<br />';
int(1)
array(0) { }
UPDATE
Someone executed my command in the terminal and got the following response:
convert: Postscript delegate failed `/home/data/websites/www/meonline.be/public_html/images/magazines/HogeschoolPromotorenP-studenten.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/713.
convert: no images defined `/home/data/websites/www/meonline.be/public_html/images/magazines/big/fs5Jd_HogeschoolPromotorenP-studenten.pdf/hogeschoolpromotorenp-studenten_1399455323_1.jpg' @ error/convert.c/ConvertImageCommand/3150.
I'm 100% sure that the PDF file exists and the second line complains about the image not being defined, but this command should create them for me.
[0]in a filename. You may not, but no-one else has any ideas yet so maybe try_0in place of[0].convert? Dowhich convertvia SSH if you can. If not I believe you can do$convertPath = 'which convert';in PHP (but use backticks rather than apostrophes to run it as a console command - backticks won't show up in comments).:). Just tried it on Ubuntu, works fine.