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!
Convert PDF to image
Re: Convert PDF to image
Do you need to convert the entire PDF or just the first page? If its just the first page add [0] to your filename (e.g. 'image.pdf[0]') and only the first page is rendered speeding up the process. If you need to render the entire PDF, the process can be slow-- ImageMagick is pushing a lot of pixels.
Re: Convert PDF to image
Thank you for your reply!magick wrote:Do you need to convert the entire PDF or just the first page? If its just the first page add [0] to your filename (e.g. 'image.pdf[0]') and only the first page is rendered speeding up the process. If you need to render the entire PDF, the process can be slow-- ImageMagick is pushing a lot of pixels.
I want to convert all pages of pdf to png. After that the user will be redirected to Flash Flipping book page and converted images will be used to view pdf like flipping book.
Is there any way to speed pdf conversion to image?
Any help will be highly appreciated.
Thanks!
Re: Convert PDF to image
Try using Ghostscript directly from the command line and bypass ImageMagick. To get started take a look at the command ImageMagick uses:
- convert -verbose image.pdf image.png