NorthShore44 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all - I'm trying to combine two PDFs in perl. Ordinarily, this would be a pretty easy task, but unfortunately, one of the PDFs I have is updated every day with a date stamp in the file name. Since I'm keeping track of these files everyday and want to keep each day's file, I want the output file to also have a date stamp in the file name. Right now, I'm using a system command with the pdftk function, but I can't get the output file to have the date stamp in the file name. Can somebody help me out? I'm pretty new to perl. Thanks!

Replies are listed 'Best First'.
Re: combining PDFs
by Your Mother (Archbishop) on Jun 30, 2010 at 15:58 UTC
Re: combining PDFs
by almut (Canon) on Jun 30, 2010 at 17:15 UTC
    I'm using a system command with the pdftk function, but I can't get the output file to have the date stamp in the file name.

    Extract the date stamp out of the respective input file name (e.g. using a regex), and put it onto the output file name that you specify in the pdftk command.

    What does your system command look like?  And what have you tried so far?

      The system line is

      system "pdftk /home/Memos/exhibit1_29JUN2010.pdf /home/Memos/exhibit2.pdf cat output /home/exhibits_29JUN2010.pdf";

      I've tried using a wildcard (*) to take the place of the datestamp (29JUN2010) in the first file's name, but I'm still having the problem of getting the combined file to have the datestamp in its name.

        Not sure I understand. Have you hardcoded those file names in the system call?  I would guess that you get the input file names from somewhere (listing directory contents, some config file, user input...).  Otherwise, how would the program work if there's a new date stamp...

        So why not simply dynamically create the output file name according to the date stamp found in the input file?  For example:

        my $in1 = "exhibit1_29JUN2010.pdf"; my $in2 = "exhibit2.pdf"; my ($date) = $in1 =~ /_([^_]+)\.pdf$/; # extract date my $out = "exhibits_$date.pdf"; # create output file name system "pdftk /home/Memos/$in1 /home/Memos/$in2 cat output /home/Memos +/$out";

        Or maybe

        my $dir = "/home/Memos"; my $in1 = <$dir/exhibit1_*.pdf>; my $in2 = "$dir/exhibit2.pdf"; my ($date) = $in1 =~ /_([^_]+)\.pdf$/; my $out = "$dir/exhibits_$date.pdf"; system "pdftk", $in1, $in2, "cat", "output", $out;