简体   繁体   English

django / python:如何使用python将pptx / docx格式转换为PDF?

[英]django/python: How to convert pptx/docx formats to PDF using python?

First of all, I agree that this might sound like a question which has already been asked many times in the past. 首先,我同意这听起来像是一个过去已经问过很多次的问题。 However I couldn't find any answer that was relevant to me in the similar questions so I'll try to be more specific. 但是,在类似的问题中我找不到与我相关的任何答案,因此我将尝试更具体。

I would need to transform PPTX/DOCX files into PDF using Python but I don't have any experience in file format conversion. 我需要使用Python将PPTX / DOCX文件转换为PDF,但是我没有任何文件格式转换经验。 I have been looking in many places/forums/websites, read a lot of documentation and came across some useful libraries ( python-pptx and pyPdf mainly), but I still don't know where to start. 我到过很多地方/论坛/网站,都阅读了很多文档,并且遇到了一些有用的库(主要是python-pptxpyPdf ),但是我仍然不知道从哪里开始。

When looking on the Internet, I can see many websites that offer file format conversions as a paying service, even with advanced API's: submit a file via POST and get the transformed PDF file in return. 在Internet上浏览时,我可以看到许多网站提供文件格式转换作为一项付费服务​​,甚至具有高级API:通过POST提交文件并获得转换后的PDF文件。 This could work for me, but I am really interested in writing myself the code that does the conversion work from OOXML to PDF. 这可能对我有用,但是我真的很想自己编写执行从OOXML到PDF转换的代码。

How would you start doing this? 您将如何开始这样做? Or is it just impossible on my own? 还是单靠我自己不可能?

Thanks for your help! 谢谢你的帮助!

After some research and with the help of python-pptx's creator, I was able to write to the PowerPoint COM interface using a Virtual Machine. 经过一些研究并在python-pptx的创建者的帮助下,我能够使用虚拟机写入PowerPoint COM界面。

In case someone reads this thread, this is how I managed to get this done: - Setup a VM with Microsoft Windows/Office installed on it ; 万一有人读了这个线程,这就是我设法做到的方式:-设置安装了Microsoft Windows / Office的VM; - Install Python, Django and win32com libraries on the VM. -在VM上安装Python,Django和win32com库。

The files are sent locally from the original Django project to the virtual machine (which are on the same network) through a simple POST request. 这些文件通过简单的POST请求从原始Django项目本地发送到虚拟机(位于同一网络上)。 The file is converted on the VM using win32com.client (which is just a simple call to the win32com.client library) and then sent back as a response to the original Django view, which in turn processes the response. 使用win32com.client(这是对win32com.client库的简单调用)在VM上转换文件,然后将其作为响应发送回原始Django视图,后者依次处理响应。

Note: it took me some time to realize I needed to use the @csrf_exempt decorator for this setup to work. 注意:我花了一些时间才意识到需要使用@csrf_exempt装饰器才能使此设置正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python 将 .docx、.xlsx、.pptx 转换为 .pdf - Converting .docx, .xlsx, .pptx to .pdf using Python 如何使用 Python 将 a.pptx 转换为 .pdf - How to convert a .pptx to .pdf using Python 将扫描的 PDF 或 tessaract 可搜索的 PDF 转换为 docx/doc 并使用 python 维护所有格式和布局 - Convert Scanned PDF or tessaract searchable PDF to docx/doc and maintaing all formats and layouts using python 使用 Python 将 PDF 转换为.docx - Convert PDF to .docx with Python 如何在 Mac OS 上使用 Python 将 docx 转换为 pdf? - How to convert docx to pdf on Mac OS with Python? 使用 Python 和 LibreOffice 将 pdf 转换为 docx 和 doc 转换为 docx 时遇到问题 - Having trouble using Python and LibreOffice to convert pdf to docx and doc to docx 错误的输出结果:在python中提取.pdf,.pptx和.docx的文本 - Incorrect output result: Text extraction for .pdf, .pptx, and .docx in python 在python中将docx文件转换为pdf - Convert the docx file into pdf in python 在 Adob​​e pdf services API 上将 .pdf 转换为 .docx(使用 Python) - Convert .pdf to .docx on Adobe pdf services API (using Python) django / python:.docx / .xlsx / .pptx的Google文档查看器问题 - django/python: Google doc viewer issue with .docx/.xlsx/.pptx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM