Convert PDF to image
Posted: 2009-03-31T04:48:01-07:00
Hi there,
We use Imagick for online pdf viewer.
Here is the code:
=============================================
public function convertPDF($pdfName, $code) {
$images = new Imagick();
$images->setResolution( 300, 300 );
$images->readImage($_SERVER['DOCUMENT_ROOT'] . "/uploads/" . $pdfName );
foreach ($images as $k => $image) {
/******************************
* CREATE THE IMAGE
****************************/
$image->setImageFormat("png");
$image->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
$image->setImageResolution(150, 150);
// Write out large image, go on.
$large_image = $_SERVER["DOCUMENT_ROOT"] . "/pdf-reader/pages/large/" . $code . "_" . $k . "_.png";
$image->thumbnailImage(NULL, 1403);
$image->writeImage($large_image);
// Write out small image, go on.
$small_image = $_SERVER["DOCUMENT_ROOT"] . "/pdf-reader/pages/" . $code . "_" . $k . "_.png";
$image->thumbnailImage(NULL, 584);
$image->writeImage($small_image);
}
$image->clear();
$image->destroy();
}
=============================================
But we are having problem when we try to convert larger pdfs. For example about 0.5-1 MB pdfs with images.
It takes long to convert pdf into png.
I am a newbie for Imagick and Image Magick.
Any help will be highly appreciated.
Thanks!
We use Imagick for online pdf viewer.
Here is the code:
=============================================
public function convertPDF($pdfName, $code) {
$images = new Imagick();
$images->setResolution( 300, 300 );
$images->readImage($_SERVER['DOCUMENT_ROOT'] . "/uploads/" . $pdfName );
foreach ($images as $k => $image) {
/******************************
* CREATE THE IMAGE
****************************/
$image->setImageFormat("png");
$image->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
$image->setImageResolution(150, 150);
// Write out large image, go on.
$large_image = $_SERVER["DOCUMENT_ROOT"] . "/pdf-reader/pages/large/" . $code . "_" . $k . "_.png";
$image->thumbnailImage(NULL, 1403);
$image->writeImage($large_image);
// Write out small image, go on.
$small_image = $_SERVER["DOCUMENT_ROOT"] . "/pdf-reader/pages/" . $code . "_" . $k . "_.png";
$image->thumbnailImage(NULL, 584);
$image->writeImage($small_image);
}
$image->clear();
$image->destroy();
}
=============================================
But we are having problem when we try to convert larger pdfs. For example about 0.5-1 MB pdfs with images.
It takes long to convert pdf into png.
I am a newbie for Imagick and Image Magick.
Any help will be highly appreciated.
Thanks!