之前我们推荐过多个不同转换方法,标题就顺着来,大家可以拣自己方便的使。
Python中已经有很多现成可以使用包或者代码了,简单上手:
git clone git@github.com:simpleapples/pdf2word.git
pip install -r requirements.txt
python main.py
# 安装
pip install pdfminer3k
使用起来相对来说麻烦一点,基础用法如下:
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfdevice import PDFDevice
# Open a PDF file.
fp = open('test.pdf', 'rb')
# Create a PDF parser object associated with the file object.
parser = PDFParser(fp)
# Create a PDF document object that stores the document structure.
# Supply the password for initialization.
document = PDFDocument(parser, password)
# Check if the document allows text extraction. If not, abort.
if not document.is_extractable:
raise PDFTextExtractionNotAllowed
# Create a PDF resource manager object that stores shared resources.
rsrcmgr = PDFResourceManager()
# Create a PDF device object.
device = PDFDevice(rsrcmgr)
# Create a PDF interpreter object.
interpreter = PDFPageInterpreter(rsrcmgr, device)
# Process each page contained in the document.
for page in PDFPage.create_pages(document):
interpreter.process_page(page)
相对于封装的软件,python和R的操作需要稍微折腾一下。浏览论坛的时候的发现了一款轻量级程序,尝试了一下还不错,看一下转换的效果:
相较于在线有部分限制的使用方式,软件提供更好的隐私性及转换效率。除了转换格式外,该软件还支持:
.PDF压缩 .PDF转word/excel/ppt/图片 .PDF文件中图片提取 .PDF文件合并/拆分 .OCR文字识别 .PDF文件去水印 .图片转PDF
软件下载地址回复【uPDF下载】即可获得。
原作者的几点说明: 1、关于报毒:程序做了加密和打包,绿色单文件,无需安装,方便携带,无毒,火绒测试通过,报毒的自行判断。 2、关于软件无法启动:多属于系统环境问题,win7 和 win10 都测试通过,如果启动不了,可能是系统缺少运行库,可按提示自行解决。 3、软件免费使用,没有任何水印、页数限制或试用期限制,严禁倒卖,或者反编译后加入收费功能。
上期我们通过 python-docx 包操作word文档,要将word再转回PDF,可以使用另一个包docx2pdf,代码很精简。
from docx2pdf import convert
convert("input.docx", "output.pdf")
其实导出pdf格式不难,如果还有什么操作PDF的好方法欢迎大家在留言区讨论,我们下期见。