2 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
另一個(gè)可以使用的是libreoffice,但是正如第一響應(yīng)者所說,質(zhì)量永遠(yuǎn)不會像使用實(shí)際的comtypes那樣好。
無論如何,在安裝libreoffice之后,這里是執(zhí)行此操作的代碼。
from subprocess import Popen
LIBRE_OFFICE = r"C:\Program Files\LibreOffice\program\soffice.exe"
def convert_to_pdf(input_docx, out_folder):
p = Popen([LIBRE_OFFICE, '--headless', '--convert-to', 'pdf', '--outdir',
out_folder, input_docx])
print([LIBRE_OFFICE, '--convert-to', 'pdf', input_docx])
p.communicate()
sample_doc = 'file.docx'
out_folder = 'some_folder'
convert_to_pdf(sample_doc, out_folder)
添加回答
舉報(bào)