http://www.perlmonks.org?node_id=920813

ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

I'm using PDF::API2 to create documents that are non-letter sized. Even though the pages are the correct size, when I go into the print dialog box of the open document, the paper size/type/etc is still set to letter and the printer can't automatically pick the correct printer tray.

Is there a way to programatically set these fields?

update

Here's my current code:

foreach (@data){ $line=144; $page= $pdf->page(); $page->mediabox('Legal'); $page->trimbox('Legal'); ... }

Replies are listed 'Best First'.
Re: PDF::API2 page setup
by Perlbotics (Archbishop) on Aug 17, 2011 at 23:12 UTC

    The PDF::API2 doc has something to say about setting the mediabox. Does invoking this method improve the situation?

    $pdf->mediabox($name) $pdf->mediabox($w, $h) $pdf->mediabox($llx, $lly, $urx, $ury)

    Sets the global mediabox.

    Example:

    $pdf = PDF::API2->new(); $pdf->mediabox('A4'); ... $pdf->saveas('our/new.pdf'); $pdf = PDF::API2->new(); $pdf->mediabox(595, 842); ... $pdf->saveas('our/new.pdf'); $pdf = PDF::API2->new; $pdf->mediabox(0, 0, 595, 842); ... $pdf->saveas('our/new.pdf');

      That's exactly how I'm already setting the page size (I'm not aware of any other way to do it), but the print dialog box isn't recognizing the settings. Like I said, the pages are setup with the right size, the problem is in the print dialog box. It keeps trying to print to "Letter" for everything, no matter the size.
        It might also help to set the trimbox as well.

        To quote PDF page boxes:

        "The TrimBox defines the intended dimensions of the finished page. Contrary to the CropBox, the TrimBox is very important because it defines the actual page size."
Re: PDF::API2 page setup
by Neighbour (Friar) on Aug 18, 2011 at 10:24 UTC
    If you're printing from adobe's acrobat reader, try unchecking the option 'Choose paper source by PDF page size'. (Or adjust the page size to match :))
      That worked! However, it would be nice if Adobe would allow that to be a document setting like Word & WordPerfect do and not a workstation setting.