浅谈Python处理PDF的方法

yipeiwu_com6年前Python基础

处理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命令方法分享等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!

相关文章

解决phantomjs截图失败,phantom.exit位置的问题

刚刚学习使用phantomjs,根据网上帖子自己手动改了一个延时截图功能,发现延时功能就是不能执行,最后一点点排查出了问题。 看代码: var page = require('web...

解决pip install的时候报错timed out的问题

安装包的时候报错,执行:pip install pyinstaller 问题: File "c:\python\python35\lib\site-packages\pip\_ven...

用Pycharm实现鼠标滚轮控制字体大小的方法

用Pycharm实现鼠标滚轮控制字体大小的方法

一、pycharm字体放大的设置 File —> setting —> Keymap —>在搜寻框中输入:increase —> Increase Font Si...

postman传递当前时间戳实例详解

postman传递当前时间戳实例详解

请求动态参数(例如时间戳) 有时我们在请求接口时,需要带上当前时间戳这种动态参数,那么postman能不能自动的填充上呢。 我们可以使用postman的pre-request scrip...

使用python实现个性化词云的方法

使用python实现个性化词云的方法

先上图片 词云图 需要模板 pip install jieba pip install wordcloud 还需要安装另外两个东西这两个我也不太懂借鉴百度写上去的 pi...