使用python将多页pdf文件拆分为多个pdf文件? [英] split a multi-page pdf file into multiple pdf files with python?

查看:883
本文介绍了使用python将多页pdf文件拆分为多个pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取多页pdf文件,并每页创建单独的pdf文件.

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

我已经下载了 reportlab 并浏览了文档,但它似乎是针对pdf生成的.我还没有看到有关处理PDF文件本身的任何信息.

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

在python中有一种简单的方法吗?

Is there an easy way to do this in python?

推荐答案

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)

这篇关于使用python将多页pdf文件拆分为多个pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆