Hi all,
I have a PDF document which I need to shift the pages to the right several inches. I.e like putting a margin on the left hand side of the page.
Can either CAM::PDF or PDF::API2 do it? Or is there anyone have experience with it?
Thanks.
Hi all,
I have a PDF document which I need to shift the pages to the right several inches. I.e like putting a margin on the left hand side of the page.
Can either CAM::PDF or PDF::API2 do it? Or is there anyone have experience with it?
Thanks.
I'm the author of CAM::PDF. The following little program shifts the page contents right by 100 points.
use CAM::PDF;
my $pdf = CAM::PDF->new('my.pdf');
my $page = $pdf->getPage(1);
$page->{MediaBox}->{value}->[0]->{value} -= 100;
$page->{MediaBox}->{value}->[2]->{value} -= 100;
$pdf->cleanoutput('out.pdf');
I used "use Data::Dumper; print Dumper($page);" to remind myself of the $page data structure.
You can do that also with Ghostscript. I'll give you some example commands for Windows (when using Unix, just replace gswin32c.exe
by gs
):
gswin32c.exe ^
-o input-shifted-pages-1-inch-to-left.pdf ^
-sDEVICE=pdfwrite ^
-c "<</PageOffset [-72 0]>> setpagedevice" ^
-f /path/to/input.pdf
-o
: specifies the output file. Implicitly also uses -dNOPAUSE -dBATCH -dSAFER
.-sDEVICE=...
: asks Ghostscript to output PDF.-c <<...
: a PostScript code snippet passed on the commandline to make happen the page shift-f ...
: specifies the input PDF (-f
is required after using -c
).The units used by /PageShift
are PostScript points. 72 pt == 1 inch. The value [-72 0]
shifts 72pt==1in to the left and 0in to top/bottom. Now you know how to shift 2 inches to the right:
gswin32c ^
-o input-shifted-pages-2-inches-to-right.pdf ^
-sDEVICE=pdfwrite ^
-c "<</PageOffset [144 0]>> setpagedevice ^
-f /path/to/input.pdf
Wanna shift 0.5 in to the bottom and 1 inch to the right?
gswin32c.exe ^
-o input-shifted-pages-1-inch-to-right-half-inch-down.pdf ^
-sDEVICE=pdfwrite ^
-c "<</PageOffset [72 -36]>> setpagedevice ^
-f /path/to/input.pdf