在 Python 中缩小和合并 PDF

发布于 2024-10-01 03:05:37 字数 571 浏览 0 评论 0 原文

我正在尝试将两个 A4 PDF 页面缩小并合并为一个 A4 页面,这样如果我有的话;

 _____        _____        
|     |      |     |
| p1  |      | p2  | 
|     |      |     |
|_____|      |_____|
         

我会得到;

 _____             
| p1  |    
|.....| 
| p2  |  
|_____|      

作为新的 PDF,其中一页上有两个 A5 大小的页面。类似于在纸上每页打印两页的方式。

我研究过 pypdfReportLab 但我似乎找不到如何像这样缩小和合并。

有什么提示吗?

谢谢!

I'm trying to shrink and merge two A4 PDF pages into one A4 page so that if I had;

 _____        _____        
|     |      |     |
| p1  |      | p2  | 
|     |      |     |
|_____|      |_____|
         

I would get;

 _____             
| p1  |    
|.....| 
| p2  |  
|_____|      

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.

I've looked into pypdf and ReportLab but I can't seem to find how to shrink and merge like this.

Any hints?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

几味少女 2024-10-08 03:05:37

pdfnup 有此功能(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)

pdfnup has this functionality (http://pypi.python.org/pypi/pdfnup)#

e.g.

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)
鹿童谣 2024-10-08 03:05:37

我的方法(不一定是最好的方法,但使用我可用的工具)是使用 Ghostcript 的 pdf2ps 转换为 PostScript,然后附加一个 N-up PostScript 序言(PS 是完整的编程语言,您可以重新定义“showpage”等内置函数,以将 N-up 或海报化直接添加到文档中),然后我会使用 ps2pdf 转换回来。

我暂时没有找到 PostScript N-up 实用程序的发布版本,但是您可以在 google 上搜索几个用其他语言编写的操作 PostScript 文档本身的实用程序,例如http://www.tardis.ed.ac.uk/~ajcd/psutils/

The way I would do it (not necessarily the best way, but using tools I have available) would be to use Ghostcript's pdf2ps to convert to PostScript, then append an N-up PostScript preamble (PS is a full programming language and you can redefine builtins like "showpage" to add N-up or posterization directly to a document) and then I'd convert back with ps2pdf.

Offhand I'm not finding a published version of a PostScript N-up utility, but you can google several ones written in other languages that manipulate the PostScript document itself, such as those at http://www.tardis.ed.ac.uk/~ajcd/psutils/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文