概述

Python处理PDF文件需要安装相应的库:【PyPDF2】库

使用场景

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

安装库

网站

使用说明

PyPDF2 官方文档(documentation)

学习网站

博客

# 导入相关类
from PyPDF2 import PdfFileReader, PdfFileWriter # 定义输入文件和输出文件(路径)
inputFile = 'read.pdf'
outputFile = 'write.pdf' # 获取一个 PdfFileReader 对象
pdfReader = PdfFileReader(open(inputFile, 'rb')) # 获取 PDF 的页数
pageCount = pdfReader.getNumPages()
print(pageCount) # 返回一个 PageObject
page = pdfReader.getPage(i) # 获取一个 PdfFileWriter 对象
pdfWriter = PdfFileWriter() # 将一个 PageObject 加入到 PdfFileWriter 中
pdfWriter.addPage(page) # 输出到文件中
pdfWriter.write(open(outputFile, 'wb'))

GitHub

提供了使用案例,当我们使用的时候再具体查看。

最新文章

  1. html4,xhtml,html5发展历史
  2. Android View各种尺寸位置相关的方法探究
  3. Android资料之-EditText中的inputType
  4. Winform添加Label
  5. bootstrap第一天,响应式布局,栅格系统运用
  6. OD使用心得
  7. PS4 的下载速度问题
  8. UITapGestureRecognizer 的用法
  9. QQ音乐API
  10. 理解display:inline、block、inline-block
  11. setTimeout setInterval 区别 javascript线程解释
  12. SQL SERVER SQLOS的任务调度
  13. java测试之文件操作
  14. java窗口按钮设置五个方向
  15. Python[小甲鱼-002用Python设计第一个游戏]
  16. Java基本语法-----java数据类型的转换
  17. Ambari安装HDP问题:User root is not allowed to impersonate anonymous.User: hcat is not allowed to impersonate ambari-qa
  18. Oracle 关键字、高级函数的使用
  19. 注册asp.net 4.0版本到IIS服务器中
  20. Java Web之EL

热门文章

  1. JavaScript实现的抛物线运动效果
  2. 属性(property)的特性(attribute)
  3. zabbix 3.2.4 使用详解
  4. openmp查看最大线程数量
  5. Nginx限制下载速度
  6. Android NDK开发调试
  7. VMware搭建虚拟机服务器
  8. [转] react-router4 + webpack Code Splitting
  9. some advice in work
  10. System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常