如何将多个PDF页面拼接成一个大画布一样的PDF?
我有一个32页的PDF文件,里面是我的家谱。我希望把家谱放在一张很大的PDF页面上,而不是像现在这样分成很多小页面。现在的格式是把8个美国信纸大小的页面拼在一起,4行拼接完成整个家谱。每个页面的边距都是22像素。
如果把它想象成一个表格(数字代表PDF页面的编号):
我试着写了一些Python代码来实现这个功能,但进展不大。请问我该如何把这些小页面拼接成一张大页面呢?
谢谢大家的帮助。
补充:这是我写的代码。抱歉之前没有贴出来。
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()
3 个回答
1
如果你有LaTeX的安装环境,我建议你使用以下方法:
- 使用
pdfpages
这个包, - 写一个大约10行的LaTeX脚本,
- 然后用
pdflatex
命令来执行。
LaTeX脚本
把下面的LaTeX脚本保存为 8x4-letter.tex
。记得根据需要调整 /path/to/input.pdf
的路径:
\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
命令
现在运行:
pdflatex 8x4-letter.tex
这样应该会生成一个PDF文件,名为 8x4-letter.pdf
。
如果你想在每一页周围加框,可以使用 frame=true
。如果想在页面之间增加额外的间距,可以使用 delta=10 10
或者 delta=17 11
,或者其他你觉得合适的值。你可能还想调整 scale=...
的值。
2
使用 pdf2ps
(这是Ghostscript的一部分)可以把PDF文件转换成PostScript格式。这种转换一般不会丢失任何信息。接下来,你可以使用这个链接里的方法,或者其他任何“多页”PostScript的开头部分,来重新安排你的页面。
这个示例链接结合了一个perl脚本,用来修改PostScript文件,插入一些代码片段。不过,你也可以找到更复杂的例子,这些例子会重写 showpage
,这样你就可以在文档开头直接插入你重新定义的 showpage
和开头部分。