Here's a second cut. This preserves the page size
and shrinks the graphics by 10%:
#!/usr/bin/perl
use warnings; use strict;
use PDF::API2;
my $pdf_in = PDF::API2->open('/tmp/test.pdf');
my $pdf_out = PDF::API2->new;
foreach my $pagenum (1 .. $pdf_in->pages) {
my $page_in = $pdf_in->openpage($pagenum);
#
# create new page
#
my $page_out = $pdf_out->page(0);
#
# Get the page size
#
my @mbox = $page_in->get_mediabox;
#
# Inherit mediabox
$page_out->mediabox(@mbox);
#
#
# copy page as a form. reduce slightly.
#
my $xo = $pdf_out->importPageIntoForm($pdf_in, $pagenum);
my $gfx = $page_out->gfx;
$gfx->formimage($xo,
my $_x = 20, my $_y = 20,
my $_scale = .9);
#
# Draw a box 10pt in from the edges of the page
#
$gfx->linewidth(1);
$gfx->strokecolor('#000000');
$gfx->rect($mbox[0]+10, $mbox[1]+10, $mbox[2]-20, $mbox[3]-20);
$gfx->stroke;
}
$pdf_out->saveas('/tmp/test2.pdf');
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|