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

Hello. I am using PDF::API3::Compat::API2 to try and set a cropbox using code something like this: $pdf->cropbox(100,100,200,200); Seems simple enough, but when I $pdf->saveas('croptest10.pdf'); all I get is a newly named pdf that looks like my original. Any thoughts on how I might get my old pdf saved out into a cropped version. I'm running on windows and linux. Either solution would work. Thanks a million. Scott

Replies are listed 'Best First'.
Re: pdf cropbox
by almut (Canon) on Sep 25, 2009 at 00:49 UTC

    I've never used PDF::API3::Compat::API2 myself, but as it says Compat::API2, I guess the idea is to be able to do it like you would in PDF::API2 — which would be:

    use PDF::API2; my $pdf = PDF::API2->open('uncropped.pdf'); $pdf->cropbox(100,100,500,500); $pdf->openpage(1); $pdf->saveas('cropped.pdf');

    The crucial thing is to open the respective page(s), as the cropbox will only have an effect on newly rendered objects, i.e. objects opened for modification.

    Here are the PDFs — for reference, or to play with: uncropped.pdf, cropped.pdf

Re: pdf cropbox
by ww (Archbishop) on Sep 24, 2009 at 23:25 UTC
    You just may want to provide some a minimal, compilable version of your code that displays the unsatisfactory behavior. Without that, it's exceedingly difficult to assist in tracking down the problem.

    Then, we just might (might!) be able to help you sort out the problem

    Welcome to the Monastery! Before posting again (or updating your post with appropriate notes about what you've changed) you may be well served by reading On asking for help and How do I post a question effectively? (to say nothing of Markup in the Monastery). They may help you pose your SOPW with sufficient information for those of us whose crystal balls are broken and whose psi is being rendered inoperative by the TriLateral Commission's black helicopters.