aegidel has asked for the wisdom of the Perl Monks concerning the following question:
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#!/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;
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!my $cutAt = ($ypos + 20) / 2.45;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PDF::API2 : re-sizing the mediabox once drawn/ crop pdf to actual content
by Eliya (Vicar) on Dec 14, 2011 at 17:51 UTC | |
by aegidel (Initiate) on Dec 14, 2011 at 21:15 UTC |