从命令行将DOCX文件转换为PDF [英] Converting DOCX file to PDF from command line
本文介绍了从命令行将DOCX文件转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写python脚本,并希望将DOCX转换为PDF.有什么办法吗?这是我当前的代码:
I am writing a python script and would like to convert a DOCX to PDF. Are there any ways of doing this? Here's my current code:
printer_path = 'C:\\Program Files\\Nitro\\Pro\\12\\NitroPDF.exe'
doc_path = 'Test.docx'
subprocess.call([printer_path, doc_source_path])
Nitro PDF将打开并开始转换文件,但不会完成.谢谢您的投入.
Nitro PDF will open and begin converting the file but won't finish. Thank you for any input.
为了使subprocess.call正常工作,我必须将两个输入都设为绝对路径,例如doc_path ='C:\ Documents \ Test.docx'
Edit 1: For the subprocess.call to work, I had to make both inputs absolute paths e.g. doc_path = 'C:\Documents\Test.docx'
推荐答案
如果您安装了Microsoft Word,则应该可以进行以下操作:
If you have Microsoft Word installed the following should work:
subprocess.call('docto -f "C:\Dir with Spaces\FilesToConvert\" -O "C:\DirToOutput" -T wdFormatPDF -OX .pdf', shell=True)
这篇关于从命令行将DOCX文件转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文