用Python缩小和合并PDF [英] Shrink and merge PDFs in Python
本文介绍了用Python缩小和合并PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将两张A4 PDF页面缩小并合并为一张A4页面,以便在需要时将其合并;
I'm trying to shrink and merge two A4 PDF pages into one A4 page so that if I had;
_____ _____
| | | |
| p1 | | p2 |
| | | |
|_____| |_____|
我会得到;
_____
| p1 |
|.....|
| p2 |
|_____|
作为新的PDF,在该页面上有两张A5尺寸的页面.类似于您可能在纸上每页打印两页.
As a new PDF, with two A5 sized pages on that one page. Similar to how you might print two pages per page on paper.
我已经研究了pyPDF(http://pybrary.net/pyPdf/)ReportLab(http://www.reportlab.com),但似乎找不到如何缩小和合并这样的内容.
I've looked into pyPDF (http://pybrary.net/pyPdf/) ReportLab (http://www.reportlab.com) but I can't seem to find how to shrink and merge like this.
有任何提示吗?
谢谢!
推荐答案
pdfnup具有此功能(http://pypi.python.org/pypi/pdfnup)#
pdfnup has this functionality (http://pypi.python.org/pypi/pdfnup)#
例如
from pyPdf import PdfFileWriter, PdfFileReader
from pdfnup import generateNup
output = PdfFileWriter()
input1 = PdfFileReader(file("in.pdf", "rb"))
page1 = input1.getPage(0)
page2 = input1.getPage(1)
output.addPage(page1)
output.addPage(page2)
outputStream = file("out.pdf", "wb")
output.write(outputStream)
outputStream.close()
generateNup("out.pdf", 2)
这篇关于用Python缩小和合并PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文