imageToBlob() on multi-page PDFs?
Posted: 2015-10-13T12:49:47-07:00
Hi,
I'm using PerlMagick to try convert multi-page PDFs into separate PNG files. I'm using the imageToBlob() method but am only getting the last page of the PDF file in the blob. Having Googled a bit I've seen reference about casting the result to an array (@) but I still seem to get a single element representing the last page of the PDF.
Strangely, when I use the command line utility on the same file it works file: convert IMG_0034.PDF IMG_0034_%d.PNG which results in IMG_0034_1.PNG and IMG_0034_2.PNG.
Here's the relevant bit of my code:
Any ideas?
Thanks,
Lyndon
I'm using PerlMagick to try convert multi-page PDFs into separate PNG files. I'm using the imageToBlob() method but am only getting the last page of the PDF file in the blob. Having Googled a bit I've seen reference about casting the result to an array (@) but I still seem to get a single element representing the last page of the PDF.
Strangely, when I use the command line utility on the same file it works file: convert IMG_0034.PDF IMG_0034_%d.PNG which results in IMG_0034_1.PNG and IMG_0034_2.PNG.
Here's the relevant bit of my code:
Code: Select all
...
$value = $object->get; # PDF file from AWS S3
$image=Image::Magick->new(magick=>$docType); # docType is determined from the S3 file, typically is 'pdf'
$image->Set(density=>300);
$image->BlobToImage($value);
$width = $image->Get('width');
$height = $image->Get('height');
# resize the image into roughly 1200 pixels wide
$factor = int ($width / 1200);
if($factor > 1)
{
$width = int ($width / $factor);
$height = int ($height / $factor);
}
$image->Set( Gravity => 'Center' );
$image->Resize( geometry => $width . 'x' . $height );
$image->Extent( geometry => $width . 'x' . $height );
# convert to grayscale
$image->Quantize(colorspace=>'gray');
# set output format to be PNG
$image->Set(magick=>'png');
$newValue = $image->ImageToBlob();
...
Thanks,
Lyndon