from flask import Flask, request, send_file from docx import Document from pdf2docx import Converter import os if not os.path.exists('uploads'): os.makedirs('uploads') app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def convert_docx_to_pdf(): if request.method == 'POST': file = request.files['file'] # 保存上传的docx文件 docx_path = 'uploads/input.docx' file.save(docx_path) # 将docx转换为pdf pdf_path = 'uploads/output.pdf' cv = Converter(docx_path) cv.convert(pdf_path) cv.close() return send_file(pdf_path, as_attachment=True) return ''' 将.docx文件转换为.pdf

在线将.docx文件转换为.pdf

Powered by 森林处理器
''' if __name__ == '__main__': app.run(port=7860,host='0.0.0.0')