浅谈Python处理PDF的方法

作者:威行天下 时间:2023-09-17 13:20:49 

处理pdf文档

第一、

从文本中提取文本

浅谈Python处理PDF的方法

第二、

创建PDF

两种方法

浅谈Python处理PDF的方法


#使用PdfFileWriter
import PyPDF2

pdfFiles = []
for filename in os.listdir('.'):
if filename.endswith('.pdf'):
pdfFiles.append(filename)
print(pdfFiles)
pdfWriter = PyPDF2.PdfFileWriter()

pdfFileObj = open(pdfFiles[0],'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj) # 得到PdfFileReader对象
first,end =map(int,input('从多少页到多少页(用空格隔开):').split())
for pageNum in range(first-1,end):
pageObj = pdfReader.getPage(pageNum)
pdfWriter.addPage(pageObj)
pdfOutput = open ('split_pdf.pdf','wb')
pdfWriter.write(pdfOutput)
pdfOutput.close()

浅谈Python处理PDF的方法


#使用PdfFileMerger()
import PyPDF2
merger = PyPDF2.PdfFileMerger()
a = [str(i)+'webbook.pdf'for i in range(0,124)]
for i in a:
print(i)
merger.append(open(i,'rb'))
print("合并完成第"+str(i))
with open('combintion.pdf','wb') as f:
merger.write(f)

来源:http://www.cnblogs.com/powercai/p/7787426.html

标签:python,处理,pdf
0
投稿

猜你喜欢

  • jquery 将disabled的元素置为enabled的三种方法

    2024-04-19 10:19:14
  • Python实现两款计算器功能示例

    2023-01-18 06:18:39
  • Windows下安装Django框架的方法简明教程

    2021-06-26 20:26:13
  • 数据库触发器(Trigger)的一点使用心得

    2024-01-28 14:21:29
  • pytorch实现textCNN的具体操作

    2022-08-28 17:40:00
  • python openssl模块安装及用法

    2023-07-03 12:01:04
  • Python中判断input()输入的数据的类型

    2023-03-14 17:02:15
  • 初探TensorFLow从文件读取图片的四种方式

    2021-08-06 06:04:34
  • MySQL鲜为人知的几个特殊技巧

    2009-03-09 13:22:00
  • IDEA连接不上MySQL端口号占用的解决

    2024-01-24 14:49:21
  • python map比for循环快在哪

    2021-06-16 09:39:04
  • MySQL查询条件中放置on和where的区别分析

    2024-01-25 00:22:51
  • Python中常见的导入方式总结

    2023-03-04 18:22:03
  • 判断Threading.start新线程是否执行完毕的实例

    2023-06-18 16:43:25
  • python中getattr函数使用方法 getattr实现工厂模式

    2021-02-25 00:34:30
  • 对pandas replace函数的使用方法小结

    2022-07-04 15:20:24
  • Django MEDIA的配置及用法详解

    2022-12-12 01:35:41
  • JS实现数字格式千分位相互转换方法

    2023-08-31 08:24:48
  • 详解基于webpack和vue.js搭建开发环境

    2024-04-30 10:40:15
  • Pandas中根据条件替换列中的值的四种方式

    2022-07-25 00:27:38
  • asp之家 网络编程 m.aspxhome.com