linux鐜鍩轰簬python璇█docx杞琾df
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux鐜鍩轰簬python璇█docx杞琾df相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/nic' title='nic'>nic
gen class mmu raise documents port app impwindows骞冲彴鍥犲€熷姪win32com鍏锋湁澶氱鏂规硶灏唚ord杞负pdf锛屼絾linux鐜涓嶅叿澶囨鐜锛寃in32com鍖呬篃灏唅mport澶辫触锛岄偅璇ュ浣曞仛鍛紵
# -*- coding: utf-8 -*- """ linux platform word to pdf """ import subprocess import os try: from comtypes import client except ImportError: client = None try: from win32com.client import constants, gencache except ImportError: constants = None gencache = None def doc2pdf_linux(docPath, pdfPath): """ convert a doc/docx document to pdf format (linux only, requires libreoffice) :param doc: path to document """ cmd = 鈥榣ibreoffice6.3 --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) def doc2pdf(docPath, pdfPath): """ convert a doc/docx document to pdf format :param doc: path to document """ docPathTrue = os.path.abspath(docPath) # bugfix - searching files in windows/system32 if client is None:#鍒ゆ柇鐜锛宭inux鐜杩欓噷鑲畾涓篘one return doc2pdf_linux(docPathTrue, pdfPath) word = gencache.EnsureDispatch(鈥榃ord.Application鈥? doc = word.Documents.Open(docPathTrue, ReadOnly=1) doc.ExportAsFixedFormat(pdfPath, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup, CreateBookmarks=constants.wdExportCreateHeadingBookmarks) word.Quit(constants.wdDoNotSaveChanges) if __name__ == 鈥榑_main__鈥? wordpath=鈥?var/db/Report_20191206105753.docx鈥? pdfpath=鈥?var/db鈥? doc2pdf(wordpath,pdfpath)
銆€銆€
以上是关于linux鐜鍩轰簬python璇█docx杞琾df的主要内容,如果未能解决你的问题,请参考以下文章
鍩轰簬璇嶅吀鍜屾湸绱犺礉鍙舵柉涓枃鎯呮劅鍊惧悜鍒嗘瀽绠楁硶
Spark + Hadoop,鍩轰簬WIFI鎺㈤拡鐨勫ぇ鏁版嵁鍒嗘瀽绯荤粺
NLP-BERT 璋锋瓕鑷劧璇█澶勭悊妯″瀷锛欱ERT-鍩轰簬pytorch
椋炲噷鏂规|鍩轰簬i.MX8MM鐨勬暟瀛桰P缃戠粶骞挎挱绯荤粺