用python将多页pdf文件拆分成多个pdf文件?

时间:2022-05-25 21:10:39

I'd like to take a multi-page pdf file and create separate pdf files per page.

我想要一个多页的pdf文件,并在每页创建单独的pdf文件。

I've downloaded reportlab and have browsed the documentation, but it seems aimed at pdf generation, I haven't yet seen anything about processing pdf's themselves.

我已经下载了reportlab并浏览了文档,但它似乎是针对pdf生成的,我还没有看到任何关于自己处理pdf的事情。

Is there an easy way to do this in python?

有没有一种简单的方法在python中执行此操作?

1 个解决方案

#1


80  

from PyPDF2 import PdfFileWriter, PdfFileReader

inputpdf = PdfFileReader(open("document.pdf", "rb"))

for i in range(inputpdf.numPages):
    output = PdfFileWriter()
    output.addPage(inputpdf.getPage(i))
    with open("document-page%s.pdf" % i, "wb") as outputStream:
        output.write(outputStream)

etc.

等等

#1


80  

from PyPDF2 import PdfFileWriter, PdfFileReader

inputpdf = PdfFileReader(open("document.pdf", "rb"))

for i in range(inputpdf.numPages):
    output = PdfFileWriter()
    output.addPage(inputpdf.getPage(i))
    with open("document-page%s.pdf" % i, "wb") as outputStream:
        output.write(outputStream)

etc.

等等