Created
November 10, 2010 07:19
-
-
Save i-blis/670489 to your computer and use it in GitHub Desktop.
Split double page PDF in two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; use warnings; | |
use PDF::API2; | |
my $filename = shift =~ /\.pdf$/i | |
or die "Be kind enough to provide a PDF file to split as argument\n"; | |
my $oldpdf = PDF::API2->open($filename); | |
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__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment