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

I am using PDF::API2 to create pdf files. I want to give margins for the pdf pages. Is there any function to do that or any arguments to any functions like new(), page() etc?

Replies are listed 'Best First'.
Re: PDF::API2 page margin
by Utilitarian (Vicar) on Apr 17, 2009 at 12:14 UTC
    The CropBox defines the region to which the page contents are to be clipped.
    $pdf->cropbox $name $pdf->cropbox $w, $h $pdf->cropbox $llx, $lly, $urx, $ury
    Sets the global cropbox.
      I tried cropbox. But I am not getting the pdf as my requirement. I am putting an image on the pdf's 1st page. The image is of size 612 x 792. On the pdf, I need a margin of 50 px on all the top, bottom, left and right. When I tried cropbox instead of mediabox, its the same result. #!/usr/bin/perl use CGI; use PDF::API2; my $q = new CGI; my $pdf = PDF::API2->new(); print $q->header( -type => 'application/x-pdf', -attachment => "test.pdf" ); my $page = $pdf->page; $page->mediabox(612, 792); my $gfx = $page->gfx; my $image = $pdf->image_jpeg("test.jpg"); $gfx->image($image); print $pdf->stringify; $pdf->end();