Convert PDF to HTML without losing text or format.
用springboot
把pdf2htmlEX
命令行工具包装为web
服务, 使得PDF
转HTML
更方便。
详情见: https://github.com/pdf2htmlEX/pdf2htmlEX
# 拉取镜像
docker pull bytesfly/pdf2html-service:1.0.1
# 启动
docker run --name pdf2html -p 8686:8686 -d --rm bytesfly/pdf2html-service:1.0.1
使用:
curl -o html.zip --request POST 'localhost:8686/api/pdf2html' --form 'files=@/pdfs/example.pdf'
提醒一下: /pdfs/example.pdf
指的是pdf文件所在的绝对路径
在当前目录解压html.zip
, 即可看到转换后的html
文件以及000-task.txt
。
# 下载代码
git clone https://github.com/bytesfly/pdf2html-service.git
# 进入项目
cd pdf2html-service
# 跳过单元测试打包
mvn clean package -DskipTests
# build docker image
docker build -t pdf2html-service:1.0.1 .
docker run --name pdf2html -p 8686:8686 -d --rm pdf2html-service:1.0.1
如果需要格外设置一些参数的话, 可以启动docker的时候通过-e
传进去:
# 同时启动的最大子进程数, 需要根据系统的资源合理设置(默认15)
-e PDF2HTML_MAX_PROCESS=15
# 执行/usr/local/bin/pdf2htmlEX命令时最大超时时间,单位s表示秒(默认600s)
-e PDF2HTML_COMMAND_TIMEOUT=600s
即:
docker run --name pdf2html -p 8686:8686 -e PDF2HTML_MAX_PROCESS=10 -e PDF2HTML_COMMAND_TIMEOUT=60s -d --rm pdf2html-service:1.0.1
更多配置见: resources
目录下的application.yml
文件。
(1) 查看版本
curl http://localhost:8686/api/version
(2) 查看配置
curl http://localhost:8686/api/config
(3) 上传多个pdf, 并下载html压缩包
curl -o html.zip --request POST 'localhost:8686/api/pdf2html' --form 'files=@/pdfs/001.pdf' --form 'files=@/pdfs/002.pdf' --form 'files=@/pdfs/003.pdf'
提醒一下: /pdfs/001.pdf
指的是pdf文件所在的绝对路径
(4) 查询程序暴露出来的metric
curl http://localhost:8686/api/metric
# 进入容器
docker exec -it pdf2html bash
# 查看日志目录
cd /opt/pdf2html-service/logs
# 查看转换失败的pdf
cd /tmp/pdf2html-service/failed-pdfs
# 手动调用pdf2htmlEX命令转换pdf
pdf2htmlEX --help