Multiple pages PDF how to convert first page to png

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
MrsCalahan
Posts: 9
Joined: 2009-05-13T01:28:22-07:00
Authentication code: 8675309

Multiple pages PDF how to convert first page to png

Post by MrsCalahan » 2011-12-06T01:33:10-07:00

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?

User avatar
magick
Site Admin
Posts: 11095
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick » 2011-12-06T05:20:46-07:00

You can read the first image of a multi-page PDF like this:
  • $im->Read('image.pdf[0]');

Post Reply