Page 1 of 1

Multiple pages PDF how to convert first page to png

Posted: 2011-12-06T01:33:10-07:00
by MrsCalahan
Hallo,

I try to convert a multiple page PDF (4 pages) in single PNG files.

Code: Select all

my $var_src = shift;        # PDF Path
my $var_dst = shift;        # PNG Path
my $var_res = shift || "72";
my $var_image = Image::Magick->new;
$status = $var_image->Read($var_src);
$status = $var_image->Set(density=>"$var_res");	
$status = $var_image->Set(units=>'PixelsPerInch');	
$status = $var_image->Write($var_dst);
undef $var_image;
That works fine and I get 4 PNG images:
  • 489823-0.png
    489823-1.png
    489823-2.png
    489823-3.png
But I don't need the 4 images. I only need the first Image 489823-0.png as 489823.png.
Is there any option to limit the number of output images an change the output filenames with PerlMagick?

Re: Multiple pages PDF how to convert first page to png

Posted: 2011-12-06T05:20:46-07:00
by magick
You can read the first image of a multi-page PDF like this:
  • $im->Read('image.pdf[0]');