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!

In reply to PDF::API2 : re-sizing the mediabox once drawn/ crop pdf to actual content by aegidel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.