Python分割指定页数的pdf文件方法

yipeiwu_com6年前Python基础

如下所示:

from PyPDF2 import PdfFileWriter, PdfFileReader

# 开始页
start_page = 0

# 截止页
end_page = 5

output = PdfFileWriter()
pdf_file = PdfFileReader(open("3.pdf", "rb"))
pdf_pages_len = pdf_file.getNumPages()

# 保存input.pdf中的1-5页到output.pdf
for i in range(start_page, end_page):
 output.addPage(pdf_file.getPage(i))

outputStream = open("output.pdf", "wb")
output.write(outputStream)

以上这篇Python分割指定页数的pdf文件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python之os操作方法(详解)

1. os.path.driname(path):返回路径的上一级路径字符串。   >>> os.path.dirname('D:\Games')   'D:\\'...

Python迭代和迭代器详解

迭代器 迭代器(iterator)有时又称游标(cursor)是程式设计的软件设计模式,可在容器物件(container,例如链表或阵列)上遍访的界面,设计人员无需关心容器物件的内存分配...

pytorch中tensor的合并与截取方法

pytorch中tensor的合并与截取方法

合并: torch.cat(inputs=(a, b), dimension=1) e.g. x = torch.cat((x,y), 0) 沿x轴合并 截取: x[:,...

Python中IP地址处理IPy模块的方法

安装 先下载源码,地址:ps://pypi.python.org/pypi/IPy/">https://pypi.python.org/pypi/IPy/ ,然后解压后使用命令py...

漂亮的Django Markdown富文本app插件的实现

漂亮的Django Markdown富文本app插件的实现

django-mdeditor Github地址:https://github.com/pylixm/django-mdeditor 欢迎试用,star收藏! Django-mdedi...