2 package PDF
::LabelPage
;
7 has
'pdf' => ( isa
=> 'PDF::Create',
11 has
'labels' => ( isa
=> 'ArrayRef',
13 default => sub { [] },
16 has
'rows' => ( isa
=> 'Int',
20 has
'cols' => ( isa
=> 'Int',
24 has
'top_margin' => (isa
=>'Int',
28 has
'bottom_margin' => (isa
=>'Int',
32 has
'left_margin' => (isa
=> 'Int',
36 has
'right_margin' => (isa
=> 'Int',
40 has
'page_format' => (isa
=> 'Str',
49 my $labels = $self->labels();
50 push @
$labels, $label;
51 $self->labels($labels);
53 print STDERR
"Now we have ".(scalar(@
{$self->labels()}))." labels in the page object.\n";
59 my $page = $self->pdf()->new_page(Mediabox
=>$self->pdf->get_page_size($self->page_format));
61 my ($page_width, $page_height) = @
{$self->pdf->get_page_size($self->page_format)}[2,3];
63 my $label_height = int( ($page_height - $self->top_margin - $self->bottom_margin) / $self->rows());
65 my $label_width = int( ($page_width - $self->left_margin - $self->right_margin) / $self->cols());
66 my $final_barcode_width = ($page_width - $self->right_margin - $self->left_margin) / $self->cols;
68 my @images =@
{ $self->labels() };
70 print STDERR
"Rendering page with @images labels on it\n";
71 foreach my $row (1..$self->rows()) {
72 foreach my $col (1..$self->cols()) {
73 my $label_boundary = $page_height - (($row-1) * $label_height) - $self->top_margin;
74 $page->line($page_width -100, $label_boundary, $page_width, $label_boundary);
75 my $index = ($row -1) * $self->cols() + $col -1;
76 my $image = $images[$index];
77 #print STDERR "RENDER: IMAGE: ".Data::Dumper::Dumper($image)."\n\n";
80 if (!defined($image)) { next; }
82 my $scalex = $final_barcode_width / $image->{width
};
83 my $scaley = $label_height / $image->{height
};
85 my $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
86 my $xpos = $label_width * ($col -1);
88 print STDERR
"Printing label: row $row; col $col = index $index X: $xpos. Y: $ypos\n";
90 if ($scalex < $scaley) { $scaley = $scalex; }
91 else { $scalex = $scaley; }
93 #foreach my $label_count (1..$self->cols) {
94 $page->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
102 sub need_more_labels
{
105 if (scalar(@
{$self->labels()}) < ($self->rows * $self->cols)) {