这边需要吧docx转成pdf,记录下
首先linux上需要安装对应lib
sudo apt update
sudo apt install libreoffice unoconv
import subprocess
def _cover_doc_docx_2_pdf(self,filename,ext,root_path)->any:
if ext.lower()== FILE_EXT.DOCX:
docx_path= os.path.join(root_path, os.path.join(self.upload_path, filename+ext))
pdf_path=os.path.join(root_path, os.path.join(self.upload_path, filename+FILE_EXT.PDF))
if os.path.isfile(pdf_path):
return pdf_path
command = ['sudo','unoconv', '-f', 'pdf', '--output', pdf_path, docx_path]
result = subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.stderr:
raise FileCoverError(ErrorMassage.DOCX_2_PDF_COVER_FAILED+': '+result.stderr.decode())
elif not os.path.isfile(pdf_path):
raise FileCoverError(ErrorMassage.DOCX_2_PDF_COVER_FAILED)
return pdf_path