Re: merge alternate pages from two PDF files in to one
- To: firstname.lastname@example.org
- Subject: Re: merge alternate pages from two PDF files in to one
- From: "H.S." <email@example.com>
- Date: Thu, 06 May 2010 16:28:40 -0400
- Message-id: <firstname.lastname@example.org>
- In-reply-to: <email@example.com>
- References: <firstname.lastname@example.org> <20100506195435.GA17984@think.homelan> <email@example.com>
> Andrei Popescu wrote:
>> On Thu,06.May.10, 15:48:17, H.S. wrote:
>>> Can somebody describe how to merge two PDF files into one so that odd
>>> pages are from the first file and the even ones are from the second? I
>>> am looking at pdftk, but it is not obvious to me if or how it can do this.
>> pdftk can split split and merge .pdf files, but I doubt it can do
>> exactly that. You will need to use some shell script magic.
> Yes, I was thinking as much. I would have preferred a command in pdftk
> for it.
> For the script, I think I will split the pdfs (burst) and then join by
> generating a command that has alternate files specifying the pages from
> the two pdf documents.
Here is what I came up with:
1. Split the input file into individual pages:
$> pdftk File1.pdf burst
This will produce files with names pg_0001.pdf, pg_0002.pdf ...
pg_nnnn.pdf, where nnnn is the total number of pages. I assume that
total pages are less than 9999, otherwise a large number format is
needed, I suppose.
2. Assume the reverse side is a single page file called File2.pdf.
3. Create the merged file with the following command (all above files
are in the current directory):
$> l=""; for f in pg_0*.pdf; do l="$l $f Fil2.pdf"; done; pdftk $l
the above command is a single line command. Variable "l" is the one that
has the files listed in the desired order. The output is in
MergedFile.pdf PDF file with odd pages from File1.pdf and even pages
Finally, clean up:
$> rm -f pg_*.pdf
Please reply to this list only. I read this list on its corresponding
newsgroup on gmane.org. Replies sent to my email address are just
filtered to a folder in my mailbox and get periodically deleted without
ever having been read.