Reputation: 3039
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):
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()
Upvotes: 10
Views: 3001
Reputation: 10198
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.
Upvotes: 8
Reputation: 90295
If you have a LaTeX installation around, I would recommend to use
pdfpages
package,pdflatex
command.Save the following LaTeX script as 8x4-letter.tex
. Adapt the /path/to/input.pdf
accordingly:
\documentclass{article}
\usepackage{color}
\definecolor{mygray}{rgb}{.9,.9,.9} % background color for complete poster
\pagecolor{mygray} % line must *precede* \usepackage{pdfpages}
\usepackage[final]{pdfpages} % comment out for testing
\usepackage[paperwidth=4896ppt, paperheight=3168]{geometry}
% dimensions of 8 letter widths, 4 heights
\pagestyle{plain} % do not use page numbering
\begin{document} % orig. slide sizes are 612x792 pts (Letter)
\includepdf[nup=8x4, % 8x4 grid was asked for
delta=0 0, % horiz.+vert. distance between slides
scale=0.999, % scale down for additional margins
pages={1-32}, % input document has 32 pages
noautoscale=false, % set to true if you have larger pages
frame=false] % set to true if you want frames
{/path/to/input.pdf} % filename+path cannot have spaces!
\end{document}
pdflatex
commandNow run
pdflatex 8x4-letter.tex
This should produce a PDF file, 8x4-letter.pdf
.
If you want frames around each page, use frame=true
. To add additional spacing between pages, use delta=10 10
or delta=17 11
or whatever suits you. You may want to change the value for scale=...
too.
Upvotes: 0
Reputation: 93890
Use pdf2ps
(part of Ghostscript) to convert the PDF to PostScript. This is usually a lossless transformation. Then use the techniques of http://www.tailrecursive.org/postscript/nup.html or any other "N-up" PostScript preamble to reorganize your pages.
The sample link combines a perl script to modify the PostScript to insert some snippets, but you can find more sophisticated examples which override showpage
so that you can just insert your preamble with the redefined showpage
at the start of your document.
Upvotes: 1