浅谈Python处理PDF的方法
2017-11-10 11:36
821 查看
处理pdf文档
第一、
从文本中提取文本
第二、
创建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()
#使用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)
总结
以上就是本文关于浅谈Python处理PDF的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:python先序遍历二叉树问题、python实现人脸识别代码、python执行使用shell命令方法分享等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- Python中的str与unicode处理方法
- Python读写Json涉及到中文的处理方法
- 如何用Python处理分类和回归问题?附方法和代码
- 《Python 编程快速上手 — 让繁琐工作自动化》读书笔记之【第13章 处理PDF和Word文档(2)】
- Python Image Opencv图像处理各种方法
- python简单文本处理的方法
- Python3中常用的处理时间和实现定时任务的方法的介绍
- python中字符串(str)的常用处理方法
- sqlite3 jdbc、c接口、python接口处理中文时遇到的问题及其解决方法
- python处理大数字的方法
- 浅谈python类属性的访问、设置和删除方法
- 详解使用Python处理文件目录的相关方法
- 浅谈python类属性的访问、设置和删除方法
- Python实现处理管道的方法
- Python字符串处理之count()方法的使用
- python字符串处理 join split replace的使用方法
- Python中处理字符串之islower()方法的使用简介
- Python使用 Beanstalkd 做异步任务处理的方法
- 服务器配置python时一些问题的处理方法
- python 读取视频,处理后,实时计算帧数fps的方法