#!/usr/bin/perl # pdfskip: skip the orientation of a PDF file. # # Oct 9, 2013 by FUJIWARA Teruyoshi # # Copyright: Copyright (c) 2013 FUJIWARA Teruyoshi # License: Distributes under the same terms as perl # # Requirement: Text::PDF and CAM::PDF (you can get them at the CPAN.) # (This script is tested with CAM::PDF-1.58, Text::PDF-0.29.) # # Usage: Try "pdfskip --help" for help message. # use strict; use warnings; use CAM::PDF; use Getopt::Long; my $opt_page = 1; my $opt_overwrite; my $opt_help; my ($infile, $outfile); my $msg_usage = "pdfskip [--page PAGE] [--overwrite] infile.pdf outfile.pdf"; my $msg_help = <<'EOS'; usage: pdfskip [--page=PAGE] [--overwrite] infile.pdf outfile.pdf -p, --page=PAGE specify pages to be skipped. Allowed formats are "5", "1,2,3", "2-5" and "1,2,7-". -o, --overwrite Outfile is set same as infile. If this option is specified, outfile is ignored. -h, --help Show this help and exit. EOS GetOptions('page=s' => \$opt_page, 'overwrite' => \$opt_overwrite, '--help' => \$opt_help); if ($opt_help) { print $msg_help; exit; } $infile = shift || die $msg_usage; if ($opt_overwrite) { $outfile = $infile; } else { $outfile = shift || die $msg_usage; } my $pdf = CAM::PDF->new($infile) || die "Cannot open the PDF file."; $pdf->deletePages(CAM::PDF->rangeToArray(1, $pdf->numPages(), $opt_page)); $pdf->cleanoutput($outfile);