Reputation: 996
In php using Imagick, I'm able to convert one pdf page into a jpg image at once. But I need to convert all pages of my pdf into jpg files in separate folder.
below my code
<?php
for($i=0;$i<=20;$i++){
$pdf_file = 'book.pdf';
$save_to = 'pages/tw'.$i.'.jpg';
$img = new imagick();
$img->setResolution(200,200);
$img->readImage("{$pdf_file}[$i]");
$img->scaleImage(800,0);
$img->setImageFormat('jpg');
$img = $img->flattenImages();
$img->writeImages($save_to, false);
$img->destroy();
}
?>
Above code produces results up-to 10 pages. Then it terminated by execution time of 30 secs. I cant manage php.ini
because I'm using hosting with another company.
Upvotes: 0
Views: 1340
Reputation: 11271
$mypdf = escapeshellarg( "mysafepdf.pdf" );
$newjpg = escapeshellarg( "output.jpg" );
$result = 0;
exec("convert -density 600 {$mypdf} {$newjpg} -colorspace RGB -resample 300", null, $result);
$ result will be 0 if the conversion works
-density = dpi
I hope this will help you!
PS.: This is only for one image, but you can adapt at it for your $i.
Upvotes: 1