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

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.

Replies are listed 'Best First'.
Re^2: PDF::API2 : re-sizing the mediabox once drawn/ crop pdf to actual content
by aegidel (Initiate) on Dec 14, 2011 at 21:15 UTC
    Elyia,

    thanks so much. Exactly what i was looking for and well explained to a PDF newb.

    Now i just have to figure out why the brother ql-580n won't honour the custom media sizes i define with brpapertool/lpoptions and keeps printing out 100mm of paper every time though pdfinfo shows the pdf is correctly defined. Oh well..

    Again: thanks for your input!