PDF2JPG - convert PDF to JPG images with ImageMagick


/ Published in: PHP
Save to your folder(s)

#ImageMagick must be installed on server for this operation


Copy this code and paste it in your HTML
  1. /**
  2.  * PDF2JPG script
  3.  * with ImageMagick
  4.  */
  5.  
  6. $pdf_file = './pdf/demo.pdf';
  7. $save_to = './jpg/demo.jpg'; //make sure that apache has permissions to write in this folder! (common problem)
  8.  
  9. //execute ImageMagick command 'convert' and convert PDF to JPG with applied settings
  10. exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'.$save_to.'"', $output, $return_var);
  11.  
  12.  
  13. if($return_var == 0) { //if exec successfuly converted pdf to jpg
  14. print "Conversion OK";
  15. }
  16. else print "Conversion failed.<br />".$output;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.