Skip to content

用springboot把pdf2htmlEX命令行工具包装为web服务, 使得PDF转HTML更方便。详情见:https://www.cnblogs.com/bytesfly/p/pdf2html.html

Notifications You must be signed in to change notification settings

bytesfly/pdf2html-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert PDF to HTML without losing text or format.

springbootpdf2htmlEX命令行工具包装为web服务, 使得PDFHTML更方便。

详情见: 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文件。

Http接口

(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

About

用springboot把pdf2htmlEX命令行工具包装为web服务, 使得PDF转HTML更方便。详情见:https://www.cnblogs.com/bytesfly/p/pdf2html.html

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published