python+django+word转pdf
一、思路判断word文件是否存在将word文档转为pdf二、代码import osimport pythoncomfrom docx2pdf import convert@receiver(post_save, sender=Resume)def post_save_resume(sender, instance, **kwargs):"""触发器,当管理员修改面试成绩“通过”之后触发,@rece
·
一、思路
判断word文件是否存在
将word文档转为pdf
二、代码
import os
import pythoncom
from docx2pdf import convert
@receiver(post_save, sender=Resume)
def post_save_resume(sender, instance, **kwargs):
"""触发器,当管理员修改面试成绩“通过”之后触发,@receiver第一个参数为管理员单击“保存后”触发"""
# 调用CoInitialize创建pdf文档
pythoncom.CoInitialize()
# word转pdf
if os.path.exists(filename):# 判断是否存在该word文件
pdf_filename = "%s/media/contact/recruit/%s_%d.pdf" % (os.getcwd(), instance.name, instance.id)
convert(filename, pdf_filename) # 将word转为pdf
else:
print("word文件不存在")
三、效果如下:
HTML动态生成word文档可以看我的上一篇博客:python+django+动态生成word

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)