文章目录
系统配置
- Macos M1 pro
PDF 转 HTML
- 首先给出的是不需要写任何代码就能成的
pdf2htmlEX
- 要将 PDF 文件转换为 HTML 文件,可以使用
pdf2htmlEX
工具。请注意,pdf2htmlEX 是一个可执行程序。首先,需要在计算机上安装pdf2htmlEX
。您可以访问以下链接获取安装说明:
https://github.com/pdf2htmlEX/pdf2htmlEX
- 这个我没弄成功,作者也说了在 macos 上这个 build 存在问题,大家可以避坑
- 原因是:build 的时候出现以下错误,详细说就是这个库底层其实依赖的事
poppler
的一个头文件,但是make
的时候找不到这个文件,解决办法不详
pdf2html
-
它是
Poppler
库的一部分
首先,请确保您已经安装了 Poppler。如果您还没有安装,请按照以下步骤操作: -
使用 Homebrew 安装 Poppler:
brew install poppler
- 成功后使用:
pdftohtml input.pdf output.html
- 如果报错:
zsh: command not found: pdf2html
- 就说明你的 poppler 没加到环境变量,通俗说就是你不能再电脑的任何一个位置随便调用这个功能,那么有两种方法:
- 加环境变量(我没弄)
- 使用完整的路径:
- 先找到这个 pdf2html 的确切位置:
find /opt/homebrew/ -name pdftohtml
- 然后使用完整位置重复上面的操作:
/opt/homebrew/bin/pdftohtml input.pdf output.html
PDFBox
- 使用基于 java 的
pdfbox
需要先安装 Java(如果尚未安装)。然后,按照以下步骤操作:- a. 下载 PDFBox 应用程序,我能够使用的是 2.0.27 版本,建议也下这个版本:https://pdfbox.apache.org/download.cgi#pdfboxapp
- b. 将下载的 JAR 文件(例如 pdfbox-app-2.0.27.jar)移到适当的文件夹。
- c. 运行以下命令将 PDF 文件转换为 HTML 文件:
java -jar pdfbox-app-2.0.27.jar ExtractText -html input.pdf output.html
aspose-words
-
这个有网页版的或者调用 api 都行
-
我用的是 python 调用它的 api
-
macos 不行,我用的 windows 电脑弄得
-
安装:
pip install aspose-words
然后根据我给的网页上的两行代码可以直接转
PDF 转 TXT
aspose-words
- 同样的操作,aspose 同样可以转成 txt
pypdf2
import PyPDF2
#create file object variable
#opening method will be rb
pdffileobj=open('1.pdf','rb')
#create reader variable that will read the pdffileobj
pdfreader=PyPDF2.PdfFileReader(pdffileobj)
#This will store the number of pages of this pdf file
x=pdfreader.numPages
#create a variable that will select the selected number of pages
pageobj=pdfreader.getPage(x+1)
#(x+1) because python indentation starts with 0.
#create text variable which will store all text datafrom pdf file
text=pageobj.extractText()
#save the extracted data from pdf to a txt file
#we will use file handling here
#dont forget to put r before you put the file path
#go to the file location copy the path by right clicking on the file
#click properties and copy the location path and paste it here.
#put "\\your_txtfilename"
file1=open(r"C:\Users\SIDDHI\AppData\Local\Programs\Python\Python38\\1.txt","a")
file1.writelines(text)
PDF 转 docx
pdf2docx
- 非常好用的工具:pdf2docx