python修改pdf内容_python3.6调整字体Python处理pdf文件库 - PyPDF2详解

PyPDF2是一个用于处理PDF文件的Python库,支持读取、写入、合并、分割PDF文档。本文介绍了如何使用PyPDF2进行简单读写、合并分割PDF,并给出了相关代码示例。
摘要由CSDN通过智能技术生成

工作中可能会涉及处理pdf文件,PyPDF2就是这样一个库, 使用它可以轻松的处理pdf文件,它提供了读、写、分割、合并、文件转换等多种操作。官方地址:http://mstamy2.github.io/PyPDF2/

安装

1. RPM式系统(Redhat、CentOS)pip install pypdf2

2. DEB式系统(Debian、Ubuntu)以下任一pip install pypdf2

apt install python-pypdf2

3. Windowspip install pypdf2

使用

PyPDF2 包含了 PdfFileReader PdfFileMerger PageObject PdfFileWriter 四个常用的主要 Class。

简单读写from PyPDF2 import PdfFileReader, PdfFileWriter

readFile = 'read.pdf'

writeFile = 'write.pdf'

# 获取一个 PdfFileReader 对象

pdfReader = PdfFileReader(open(readFile, 'rb'))

# 获取 PDF 的页数

pageCount = pdfReader.getNumPages()

print(pageCount)

# 返回一个 PageObject

page = pdfReader.getPage(i)

# 获取一个 PdfFileWriter 对象

pdfWriter = PdfFileWriter()

# 将一个 PageObject 加入到 PdfFileWriter 中

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值