PDF::API2 and Landscape

I’m currently working on a way to generate a custom PDF of a Bugzilla record (which, in turn, contains a bunch of custom fields). One of the requirements of the spec is that the PDF is targeted at US letter size paper in landscape orientation. I’m looking at using PDF::API2 and PDF::Table but one of the problems I had, just like manu, is that when you call $page->rotate(90) it sure-enough rotates the page at render time, but it’s really as if you printed on a portrait-oriented page and then turned the page sideways. This is not what one expects, since this is not, at the end of the day, something that one has much call to do.

Here’s how to achieve the actually desired effect: set the mediabox manually to the appropriate settings for a landscape orientation.

$page = $pdfdoc->page();
$page->mediabox(0, 0, 11*72, 8.5*72);

In my code I’ve defined a function that returns that list so that the code can be a little more descriptive:

sub LETTER_LANDSCAPE {
    return (0, 0, 11*72, 8.5*72);
}

...
$page = $pdfdoc->page();
$page->mediabox(LETTER_LANDSCAPE());

There’s probably a prettier way to do it, but at least this works. Gotta ship code, man.

Published by pirateguillermo

I play the bagpipes. I program computers. I support my family in their various endeavors, and I enjoy my wonderful life.

One thought on “PDF::API2 and Landscape

Leave a Reply Cancel reply