or the documentation PDF::TableX#!/usr/bin/env perl -w # this extends the regular text cell with image capabilities package ImageContent; use Moose::Role; use PDF::API2; sub draw_content { my ($self, $x, $y, $gfx, $txt) = @_; $y -= ($self->padding->[0] + 200); $x += $self->padding->[3]; if ($y < $self->margin->[2]) { return (200, $self->height, 1); } else { my $image_object = $gfx->{' api'}->image_jpeg( $self->content +); $gfx->image($image_object, $x, $y, 200, 200); $self->height(200+$self->padding->[0]+$self->padding->[2]); return (200, $self->height, 0); } } sub _get_min_width { 200 + $_[0]->padding->[1] + $_[0]->padding->[3] } sub _get_reg_width { 200 + $_[0]->padding->[1] + $_[0]->padding->[3] } sub _get_height { 200 + $_[0]->padding->[0] + $_[0]->padding->[2] } # the actual script to build the page use Moose::Util qw( apply_all_roles does_role); use PDF::TableX; use PDF::API2; my $contents = [ ['http://something/something', 'img.jpg'], ['http://something/something', 'img1.jpg'], ['http://something/something', 'img2.jpg'], ['http://something/something', 'img3.jpg'], ]; my $table = PDF::TableX->new(2,4); my $pdf = PDF::API2->new(); $pdf->mediabox('a4'); my $page = $pdf->page; $table ->padding(0) ->border_width(0) ->text_align('center'); $table->[0]->border_width(0); foreach my $i (0..3) { foreach my $j (0..1) { if ($j == 1) { apply_all_roles( $table->[$i][$j], 'ImageConten +t'); } $table->[$i][$j]->content($contents->[$i][$j]); } } $table->draw($pdf, $page); $pdf->saveas('output.pdf');
In reply to Re: Add images to PDF using pdf::ap12
by gpapkala
in thread Add images to PDF using pdf::ap12
by cristofayre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |