Hello all,
i'm trying to create a label-sized pdf printout (brother ql 580n, 62mm media endless paper) under debian 2.6.39-bpo.2-686-pae with perl v5.10.1 (*) built for i486-linux-gnu-thread-multi that
dynamically adjusts the page height based on content.
So far i have
#!/usr/bin/perl
use strict;
use warnings;
use PDF::API2;
use PDF::TextBlock;
use constant mm => 25.4 / 72;
use constant in => 1 / 72;
use constant pt => 1;
my ( $paragraph1, $paragraph2) = ('Headertext', 'Testtext zur Ausgabe
+in einem selbstgebauten PDF mit den richtigen Maßen. Mal sehen, was d
+as gibt! ÄÜÖüäößéèàá');
my $pdf = PDF::API2->new( -file => "./test.pdf" );
my $page = $pdf->page;
$page->mediabox (62/mm, 100/mm);
#$page->cropbox (2/mm, 4/mm, 60/mm, 92/mm); # printable area
my %font = (
Helvetica => {
Bold => $pdf->corefont( 'Helvetica-Bold', -encoding => 'latin
+1' ),
},
Times => {
Roman => $pdf->corefont( 'Times', -encoding => 'latin1' ),
},
);
# do some umlaut conversions here .... (snipped)
my $tb = PDF::TextBlock->new({
pdf => $pdf,
page => $page,
fonts => {
b => PDF::TextBlock::Font->new({
pdf => $pdf,
font => $font{'Helvetica'}{'Bold'},
size => 16/pt,
fillcolor => '#000000',
}),
p => PDF::TextBlock::Font->new({
pdf => $pdf,
font => $font{'Times'}{'Roman'},
size => 14/pt,
fillcolor => '#000000',
}),
},
});
$tb->text(
"<b>$paragraph1</b>\n\n<p>$paragraph2</p>"
);
# set the start of the paragraph and maxwidth/ height
$tb->x(7/mm);
$tb->y(82/mm);
$tb->w(50/mm);
$tb->h(95/mm);
my ($endw, $ypos) = $tb->apply;
$pdf->save;
$pdf->end;
All my tries (recalling mediabox, trimbox etc after $tb->apply etc) so far have ended up cropping the top part of the pdf (due to 0.0 origin at bottom left i suppose) or resizing to letter..
However, calculating a cut-off region by doing
my $cutAt = ($ypos + 20) / 2.45;
i would like to resize the PDF to the width=62 mm (as defined, doesn't change) and height=$cutAt (e.g. 60mm) FROM THE TOP.
I've been trying without success, any ideas on how this can be achieved?
Thanks!