Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stitch several PDF pages into one big canvas-like PDF?

I have a 32-page PDF of my family tree. Instead of having the family tree all on one really big PDF page (which is what I want), it is formatted so a group of 8 individual US letter-sized pages are supposed to be stitched across the width; 4 rows of this completes the tree. The margins of each page are all 22px.

If you visualize it in table form (where the numbers represent PDF page numbers):

table

I've tried to whip up some Python code to do this, but haven't gotten very far. How can I stitch the PDF so it can be one big page instead of smaller individual pages?

Thanks for the help.

EDIT: Here's the code I wrote. Sorry for not originally posting it.

from pyPdf import PdfFileWriter, PdfFileReader

STITCHWIDTH = 8;
currentpage = 1;

output = PdfFileWriter()
input1 = PdfFileReader(file("familytree.pdf", "rb"))

for(i=0; i<=4; i++)
    output.addPage(input1.getPage(currentpage))
    currentpage++;
    #do something to add other pages to width

print "finished with stitching"

outputStream = file("familytree-stitched.pdf", "wb")
output.write(outputStream)
outputStream.close()
like image 793
hao_maike Avatar asked Jul 05 '11 00:07

hao_maike


1 Answers

As an alternative to Ben Jackson's suggestion of first converting to PostScript, and doing an "N-up" transform on the PostScript files, there's also a script called pdfjam, that can operate directly on PDF files.

Example:

pdfjam --nup 8x4 --landscape --outfile output.pdf input.pdf

The script is a wrapper for the pdfpages LaTeX package, recommended in another answer.

like image 183
Jukka Matilainen Avatar answered Nov 02 '22 20:11

Jukka Matilainen