A PDF MediaBox is represented by four parameters: x,y of the lower left corner, and x,y of the upper right corner (with 0,0 being located at the bottom left of the page).  And $page->mediabox(62/mm, 100/mm) is a short form of saying $page->mediabox(0, 0, 62/mm, 100/mm).

If you need to reduce the MediaBox at its bottom end, you don't want the lower left corner to be 0,0, so you have to use the four argument version of $page->mediabox().

62mm,100mm --------------------- | | | This is your | | | | textblock | | | | foo bar baz | | | | end. | | | 0,$ypos|.....................| | | | | | | | | --------------------- 0,0

In other words, if I'm understanding your requirements correctly, all you need is

... my ($endw, $ypos) = $tb->apply; $page->mediabox(0, $ypos, 62/mm, 100/mm); # <--- $pdf->save; $pdf->end;

(AFAICT, $ypos - as returned by $tb->apply() - is the current y-position (cursor) after the block has been rendered, i.e. your y-coordinate of the lower left corner.)

Update: just tested it, and it works fine for me.


In reply to Re: PDF::API2 : re-sizing the mediabox once drawn/ crop pdf to actual content by Eliya
in thread 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.