1

I try to convert pdf to docx with Libreoffice,and I use this method provided at Convert PDF to DOC (Python/Bash) ,the code is as follows:

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)

However, when I debug it, I get an error:

Error: source file could not be loaded
Error: no export filter for C:\Users\owner\desktop\docx\my.docx found, aborting.
Error: no export filter

I've searched this using Google a while,however there is no any answer fit to my question.So I'm here asking for help. Thanks a lot!

Josh Karpel
  • 2,110
  • 2
  • 10
  • 21
yongchun zha
  • 41
  • 1
  • 6
  • The code says `--convert-to doc` but you are converting to docx? It looks like you did not post the actual code used. Also, does the problem occur when you run a single lowriter command from the command line? Post the single command as well. – Jim K Sep 06 '17 at 19:11
  • Thanks! Actually I've tried `--convert-to doc` and '--convert-to docx' ,I must have posted the code for 'doc' and the error message for 'docx'.My mistake!And I can make sure it is not this problem.And as you suggested,I've tried to run the 'lowriter' command in the command line.the same error occurs! – yongchun zha Sep 07 '17 at 03:20

1 Answers1

0

Give export filter for pdf to search file in your directory...

for example:

subprocess.call('lowriter --invisible --convert-to doc:writer_pdf_export "{}"' .format(abspath), shell=True)

or

subprocess.call('lowriter --invisible --convert-to doc:draw_pdf_export "{}"' .format(abspath), shell=True)