Alex Rivera | Logout

How can I combine two PDF pages show up on the same page?

Asked 2009-02-11T07:38:37.670
29

I am looking for a free tool that allows re-arranging pages of a PDF document and combining multiple pages per sheet. The first part (re-arranging) is easily solved by many tools (I use PyPDF).

The problem is with the second requirement: to combine two (or more) pages into single page. For example, take two pages (A and B), rotate them, scale and combine into a single page like this

------       ------            ------
|     |      |      |          |     |
|  A  |      |  B   |          | a   |
|     |      |      |          |     |
|     |      |      |  --->    ------
|     |      |      |          |     |        
|     |      |      |          | b   |        
|     |      |      |          |     |        
------       ------            ------

The solution needs to work on Linux and preferably on Windows too. I'm looking for either console application or library with Python or Perl bindings.

Edit there is pdfnup library that is supposed to perform exactly this kind of transformation, and is cross-platform, however I cannot use it due to a bug similar to this.

Edit
Report

1 Answer

0

This is a perl function I use to grab a directory full of prn files from a 3rd party app and create a single merged pdf.

sub runMerged($)
{
    my($path) = @_;

    print "Generating merged PDFs for $path\n";

    my @files = sort(getFiles($path, ".prn\$"));
    if (scalar(@files))
    {
        open(MERGE, ">$path/merged.prn");
        for (my $i = 0; $i < scalar(@files); $i++)
        {
            print MERGE "^L\n" if ($i > 0);

            open(FN, "$path/" . $files[$i]);
            while (my $line = <FN>)
            {
                print MERGE $line;
            }
            close(FN);
        }

        chdir("$BASE_PATH/txt2pdf");
        print `./txt2pdf.pl $path/merged.prn`;
    }
}
answered 2009-02-13T11:55:57.393

Your Answer