python实现pdf转word_使用Python将PDF转换为.docx

I'm trying very hard to find the way to convert a PDF file to a .docx file with Python.

I have seen other posts related with this, but none of them seem to work correctly in my case.

I'm using specifically

import os

import subprocess

for top, dirs, files in os.walk('/my/pdf/folder'):

for filename in files:

if filename.endswith('.pdf'):

abspath = os.path.join(top, filename)

subprocess.call('lowriter --invisible --convert-to doc "{}"'

.format(abspath), shell=True)

This gives me Output[1], but then, I can't find any .docx document in my folder.

I have LibreOffice 5.3 installed.

Any clues about it?

Thank you in advance!

解决方案

I am not aware of a way to convert a pdf file into a Word file using libreoffice.

However, you can convert from a pdf to a html and then convert the html to a docx.

Firstly, get the commands running on the command line. (The following is on Linux. So you may have to fill in path names to the soffice binary and use a full path for the input file on your OS)

soffice --convert-to html ./my_pdf_file.pdf

then

soffice --convert-to docx:'MS Word 2007 XML' ./my_pdf_file.html

You should end up with:

my_pdf_file.pdf

my_pdf_file.html

my_pdf_file.docx

Now wrap the commands in your subprocess code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值