1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| """ linux system word to pdf """ import subprocess def doc2pdf_linux(docPath, pdfPath): """ convert a doc/docx document to pdf format (linux only, requires libreoffice) :param doc: path to document """ cmd = 'libreoffice --headless --convert-to pdf'.split() + [docPath] + ['--outdir'] + [pdfPath] p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) p.wait(timeout=30) stdout, stderr = p.communicate() if stderr: raise subprocess.SubprocessError(stderr) if __name__ == '__main__': wordpath='/data/demo.docx' pdfpath='/data/test/' doc2pdf_linux(wordpath,pdfpath)
|