/ Published in: Perl
Each page is split vertically in two pages. Crop and media views are set accordingly. Text layer should be preserved.
Takes a path to a PDF file as argument and produces a cropped PDF in the same location.
Takes a path to a PDF file as argument and produces a cropped PDF in the same location.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env perl use strict; use warnings; use PDF::API2; my $newpdf = PDF::API2->new; for my $page_nb (1..$oldpdf->pages) { my ($page, @cropdata); $page = $newpdf->importpage($oldpdf, $page_nb); @cropdata = $page->get_mediabox; $cropdata[2] /= 2; $page->cropbox(@cropdata); $page->trimbox(@cropdata); $page->mediabox(@cropdata); $page = $newpdf->importpage($oldpdf, $page_nb); @cropdata = $page->get_mediabox; $cropdata[0] = $cropdata[2] / 2; $page->cropbox(@cropdata); $page->trimbox(@cropdata); $page->mediabox(@cropdata); } (my $newfilename = $filename) =~ s/(.*)\.(\w+)$/$1.clean.$2/; $newpdf->saveas('$newfilename'); __END__