| PDF-FromImage documentation | Contained in the PDF-FromImage distribution. |
PDF::FromImage - Create PDF slide from images
use PDF::FromImage;
my $pdf = PDF::FromImage->new;
$pdf->load_images(
'page1.png',
'page2.png',
:
);
$pdf->write_file('output.pdf');
This module create simple pdf image slide from multiple images.
Load a image file.
Supported format are jpeg, tiff, pnm, png, and gif.
Load multiple images.
Generate pdf from loaded images, and write it to file.
Daisuke Murase <typester@cpan.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| PDF-FromImage documentation | Contained in the PDF-FromImage distribution. |
package PDF::FromImage; use 5.008001; use Moose; our $VERSION = '0.000003'; use PDF::API2; use Imager; use PDF::FromImage::Image; has images => ( is => 'rw', isa => 'ArrayRef', lazy => 1, default => sub { [] }, );
sub load_image { my ($self, $image) = @_; my $imager = Imager->new; $imager->read( file => $image ) or confess $imager->errstr; my $format = $imager->tags( name => 'i_format' ); my $supported = grep { $_ eq $format } qw/jpeg tiff pnm png gif/; confess qq{This module doen't support "$format"} unless $supported; my $image_object = PDF::FromImage::Image->new( src => $image, format => $format, width => $imager->getwidth, height => $imager->getheight, ); push @{ $self->images }, $image_object; }
sub load_images { my $self = shift; $self->load_image($_) for @_; }
sub write_file { my ($self, $filename) = @_; confess 'no image is loaded' unless @{ $self->images }; my $pdf = PDF::API2->new; for my $image (@{ $self->images }) { my $page = $pdf->page; $page->mediabox( $image->width, $image->height ); my $loader = 'image_' . $image->format; my $img = $pdf->$loader($image->src); my $gfx = $page->gfx; $gfx->image( $img, 0, 0 ); } $pdf->saveas($filename); $pdf->end; }
1;