Home  >  Article  >  Backend Development  >  How to convert php pdf to jpg

How to convert php pdf to jpg

藏色散人
藏色散人Original
2020-10-13 15:33:413084browse

php How to convert pdf to jpg: first install the Image Magick extension; then convert via "exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'...)" That’s it.

How to convert php pdf to jpg

Recommended: "PHP Video Tutorial"

This is a very simple format conversion code, You can convert .PDF files to .JPG files. For the code to work, the server must have the Image Magick extension installed.

$pdf_file  = './pdf/demo.pdf';
$save_to  = './jpg/demo.jpg';
//make sure that apache has permissions to write in this folder! 
//(common problem)
  
//execute ImageMagick command 'convert' and convert PDF
//to JPG with applied settings
exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'.$save_to.'"', $output, $return_var);
  
if($return_var == 0) {
//if exec successfuly converted pdf to jpg
  print "Conversion OK";
}
else print "Conversion failed.".$output;

The above is the detailed content of How to convert php pdf to jpg. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn