Skip to content

Instantly share code, notes, and snippets.

@xxsimoxx
Created March 1, 2022 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xxsimoxx/769b6b45c9990a60d481f1cb8b50d60c to your computer and use it in GitHub Desktop.
Save xxsimoxx/769b6b45c9990a60d481f1cb8b50d60c to your computer and use it in GitHub Desktop.
Separa un PDF in due files in base a step.
#!/usr/bin/perl
use strict;
use warnings;
use PDF::API2;
my ($pdf, $step) = @ARGV;
if (not defined $pdf) {
die "Need file name\n";
}
if (not defined $step) {
die "Need steps\n";
}
my $file = PDF::API2->open($pdf);
my $pag = $file->pages();
my @range=(1..$pag);
my $cmd_lettere = "pdftk ${pdf} cat ";
my $cmd_bollettini = "pdftk ${pdf} cat ";
foreach(@range){
if($_%$step == 1){
$cmd_lettere .= "$_ ";
}
}
foreach(@range){
if($_%$step != 1){
$cmd_bollettini .= "$_ "
}
}
$pdf =~ s/\.pdf$//;
$cmd_lettere .= "output ${pdf}-lettere.pdf";
$cmd_bollettini .= "output ${pdf}-bollettini.pdf";
print "\n$cmd_lettere\n\n$cmd_bollettini\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment