PDF转成html和 text 的工具汇总

系统配置

  • Macos M1 pro

PDF 转 HTML

  • 首先给出的是不需要写任何代码就能成的

pdf2htmlEX

  • 要将 PDF 文件转换为 HTML 文件,可以使用 pdf2htmlEX 工具。请注意,pdf2htmlEX 是一个可执行程序。首先,需要在计算机上安装 pdf2htmlEX。您可以访问以下链接获取安装说明:

https://github.com/pdf2htmlEX/pdf2htmlEX

  • 这个我没弄成功,作者也说了在 macos 上这个 build 存在问题,大家可以避坑
  • 原因是:build 的时候出现以下错误,详细说就是这个库底层其实依赖的事 poppler 的一个头文件,但是 make 的时候找不到这个文件,解决办法不详
    f

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

在这里插入图片描述

其他

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暖仔会飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值