Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PDF to JPG image with PHP

I am using ImageMagik to try and convert the contents of a PDF to JPG, but keep getting an empty jpg. I have made sure the perms are 777 on everything for testing so I am a little lost how to continue.

Here is the script I am running

<?php

    exec('convert testfile.pdf output.jpg', $output, $return_var);

?>
like image 916
tony2 Avatar asked Feb 18 '23 08:02

tony2


2 Answers

Try this.

<?php
    $pdf = 'testfile.pdf';
    $save = 'output.jpg';

    exec('convert "'.$pdf.'" -colorspace RGB -resize 800 "'.$save.'"', $output, $return_var);

?>
like image 98
Errol Fitzgerald Avatar answered Feb 24 '23 17:02

Errol Fitzgerald


Use the absolute path to the binary, like this:

exec('/usr/bin/convert testfile.pdf output.jpg', $output, $return_var);

But make sure your convert binary is actually on /usr/bin you can check that out with the following command:

which convert

like image 36
Nelson Avatar answered Feb 24 '23 18:02

Nelson