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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |