Convert PDF to DOC (Python/Bash)

AlvaroAV picture AlvaroAV · Oct 14, 2014 · Viewed 53.4k times · Source

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

Is there any way to convert a PDF file to a DOC/DOCX file using Python or any Unix command ?

Thanks in advance

Answer

user3058846 picture user3058846 · Oct 14, 2014

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)