有做机械工装的网站吗网站载入页面怎么做
centos部署的django项目,使用libreoffice做文件转换,官网给环境安装好libreoffice后,可使用命令行来进行转化
还可转换其他的各种格式,本文只做了pdf转换
import subprocess    
import os    def convert_to_pdf(input_file, output_file):    # 检查文件扩展名    if input_file.endswith('.docx'):    extension = '-convert-to pdf'    elif input_file.endswith('.doc'):    extension = '-filter pdfimport -close-early'    else:    raise ValueError('Unsupported file format')    # 构建命令行参数    command = f'libreoffice --headless --convert-to pdf --outdir {os.path.dirname(output_file)} {input_file}{extension}'    # 运行命令行命令    try:  subprocess.run(command, shell=True)    except subprocess.CalledProcessError as e:  print(f"Error occurred while converting the document: {e}")  return False  # 检查输出文件是否存在    if not os.path.exists(output_file):    raise FileNotFoundError(f'Failed to create {output_file}')    # 使用示例    
input_file = 'path/to/input.docx'  # 替换为实际的输入文件路径    
output_file = 'path/to/output.pdf'  # 替换为实际的输出文件路径    
convert_to_pdf(input_file, output_file) 
