使用Python从Word文档输出PCL [英] Output PCL from Word document using Python

查看:985
本文介绍了使用Python从Word文档输出PCL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Web应用程序,其中包括使用MS Word(并且可能从基于Web的富文本编辑器输入)文档的功能,将值替换为这些文档中的表单字段占位符,并生成PCL文档作为输出



我正在Windows上开发python和django,但是这个整体解决方案将需要部署到一个Web主机(尚未被选中)意味着该解决方案需要在linux上运行。



如果这是唯一的办法,我可以使用仅适用于Linux的解决方案。我可以接受与使用另一种语言编写的服务器进行交谈的解决方案。如果需要,我可以编写C ++或java来完成这个任务。最终输出 必须是PCL格式。



我的问题是:什么是生成PCL的好工具链使用python的word文档



我正在考虑使用某种接口打开word文档,进行替换,并将输出发送给某些一种打印机驱动程序。有没有人有这方面的经验?您会推荐哪些图书馆?



我已经确定的接口选项包括以下内容:任何其他建议将受到极大的欢迎:





第二种方法是使用像paradocx这样的东西( https://bitbucket.org/yougov/paradocx/wiki/Home )打开word文件,使用python中的替换,然后以某种方式与可以输出PCL的东西进行接口。再次,对这种方法的任何经验或评论都将不胜感激。



我将非常感谢任何有关工具和工具链,想法或您可能拥有的食谱。



此问题涵盖类似的理由,但与...不同:如何从MS Word创建PCL文件

解决方案

OK,所以我的最终解决方案涉及创建一个java webservice来执行我的转码。




  • Docx4j 提供了一个类 org.docx4j.convert.out.pdf.viaXSLFO.Conversion 钩入 apache FOP 将Docx转换为PDF;这可以很容易地被黑客转换为PCL(因为FOP输出PCL)

  • Spark 是一个轻量级的java Web框架,允许我将我的代码转换器包裹在一个Web服务中。

  • 因为我也操纵文档,所以我需要一些元数据,所以完美的是多部分形式。我解释说,使用 Apache Fileupload



在几乎所有情况下,我不得不升级到库的开发版本,以使其正常工作。



在python端,我使用:




  • 请求 与网络服务进行通信

  • 海报 准备多部分请求


    • I'm building a web application which will include functionality that takes MS Word (and possibly input from a web-based rich text editor) documents, substitutes values into the formfield placeholders in those documents, and generates a PCL document as output.

      I'm developing in python and django on windows, but this whole solution will need to be deployed to a web host (yet to be chosen), which in practice means that the solution will need to run on linux.

      I'm open to linux-only solutions if that's the only way. I'm open to solutions that involve talking to a server written in another language. I am able to write C++ or java if necessary to get this done. The final output does have to be in PCL format.

      My question is: what is a good tool chain for generating PCL from word documents using python?

      I am considering using some kind of interface to openoffice to open the word documents, do the substitutions, and send the output to some kind of printer driver. Does anyone have experience with this? What libraries would you recommend?

      Options for interfacing that I have identified include the following; any other suggestions would be greatly welcomed:

      A second approach would be to use something like paradocx ( https://bitbucket.org/yougov/paradocx/wiki/Home ) to open the word files, do the substitutions using that in python, then somehow interface with something that can output PCL. Again, any experience or comments on this approach would be appreciated.

      I will very much appreciate any comments on tools and toolchains, and ideas or recipes that you may have.

      This question covers similar ground to, but is not the same as: How to Create PCL file from MS word

      解决方案

      OK, so my final solution involved creating a java webservice to perform my transcoding.

      • Docx4j provides a class org.docx4j.convert.out.pdf.viaXSLFO.Conversion which hooks into apache FOP to convert Docx to PDF; that can be easily hacked to convert to PCL (because FOP outputs PCL)
      • Spark is a lightweight java web framework which allowed me to wrap my transcoder in a web service
      • Because I also manipulate the document, I need to have some metadata, so the perfect thing is a multipart form. I decode that using Apache Fileupload

      In almost all cases, I had to upgrade to the development versions of libraries to get this to work.

      On the python side I use:

      • requests to communicate with the web service
      • poster to prepare the multi-part request

      这篇关于使用Python从Word文档输出PCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆