通过pdf2docx将pdf转为word同时保留表格格式
pip install pdf2docx
示例:
pdf2docx convert 1.pdf 1.docx
官方文档地址
https://dothinking.github.io/pdf2docx/quickstart.cli.html
如果command not found
将python/bin目录设置进环境变量
export
P
A
T
H
=
/
x
x
/
p
y
t
h
o
n
/
b
i
n
:
PATH=/xx/python/bin:
PATH=/xx/python/bin:PATH
java参考以下代码调用
/**
* 1.pdf 输入pdf路径
* 1.docx 输出docx路径
*/
String cmd ="pdf2docx convert 1.pdf 1.docx";
Runtime runtime = Runtime.getRuntime();
Process exec = null;
try {
exec = runtime.exec(cmd);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
exec.waitFor();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
exec.destroy();