#!/usr/bin/perl

# pdfcat: concatenate PDF files into one file.
# 
# Oct 8, 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 "pdfcat --help" for help message.
#

use strict;
use warnings;
use CAM::PDF;
use Getopt::Long;

my $infile;
my $opt_outfile = "out.pdf";
my $opt_overwrite;
my $opt_help;

my $msg_usage = "pdfcat [--outfile DEG] file1 file2 ... fileN";
my $msg_help = <<'EOS';
usage: pdfcat [--outfile FILENAME] file1 file2 ... fileN
  -o, --outfile FILENAME  Specify filename of the generated PDF.
  -h, --help              Show this help and exit.
EOS

GetOptions('outfile=s' => \$opt_outfile, '--help' => \$opt_help);
 
if ($opt_help || $#ARGV < 0) {
  print $msg_help;
  exit;
}

my $f = shift(@ARGV);
my $base = CAM::PDF->new($f);

foreach my $f (@ARGV) {
  my $pdf = CAM::PDF->new($f);
  $base->appendPDF($pdf);
} 

$base->cleanoutput($opt_outfile);