I would like to convert a pdf file to images in PHP.
I have got some exception like this:
Fatal error: Uncaught ImagickException: UnableToOpenBlob './sample.pdf': No such file or directory @ error/blob.c/OpenBlob/3533 in D:\Task\Clients\James\toImage\toImage.php:4 Stack trace: #0 D:\Task\Clients\James\toImage\toImage.php(4): Imagick->readImage('./sample.pdf') #1 {main} thrown in D:\Task\Clients\James\toImage\toImage.php on line 4
I wrote some code like as follows.
<?php
$pdf_url = ('./sample.pdf');
$imagick = new Imagick();
$imagick->readImage($pdf_url);
$imagick->resizeImage( 200, 200, imagick::FILTER_LANCZOS, 0);
$imagick->setImageFormat( "png" );
$imagick->writeImage('pdfAsImage.png');
Please help me!
CodePudding user response:
Here is the code I have ever used before. Use the full path to the image, for example:
$image = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/pdfs/sample.pdf');
It should work like a charm!!!