Skip to content

Instantly share code, notes, and snippets.

@y-yu
Last active August 29, 2015 14:04
Show Gist options
  • Save y-yu/d76eef120b14c8945b21 to your computer and use it in GitHub Desktop.
Save y-yu/d76eef120b14c8945b21 to your computer and use it in GitHub Desktop.
split.pl
#!/usr/bin/env perl
use strict;
use warnings;
my $pdffile = $ARGV[0];
my $output = $ARGV[1] ? $ARGV[1] : ".";
my ($pagesize) = `pdfinfo $pdffile` =~ m/Pages:\s* (\d+)/x;
my $tenth = int($pagesize / 10);
for (0..$tenth - 1) {
my ($x, $y) = ($_ * 10 + 1, $_ * 10 + 10);
my $cmd = "pdftk $pdffile cat $x-$y output $output/$x-$y.pdf";
print "$cmd\n";
system $cmd;
}
my $cmd = "pdftk $pdffile cat ". ($tenth*10+1). "-$pagesize output $output/". ($tenth*10+1) ."-$pagesize.pdf";
print "$cmd\n";
system $cmd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment