Search code examples
pythonbashpdfdocxdoc

Python: Convert PDF to DOC


How to convert a pdf file to docx. Is there a way of doing this using python?

I've saw some pages that allow user to upload PDF and returns a DOC file, like PdfToWord

Thanks in advance


Solution

  • If you have LibreOffice installed

    lowriter --invisible --convert-to doc '/your/file.pdf'
    

    If you want to use Python for this:

    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)