简体   繁体   English

需要帮助以使用python生成PDF或Doc报告

[英]Need help to generate report in PDF or Doc using python

I want some help to generate a report in PDF/Doc(MS Word) format . 我需要一些帮助以PDF / Doc(MS Word)格式生成报告。 I'm not able to find any module to generated report in doc, except “docx” which I'm not able to comprehend. 除了无法理解的“ docx”之外,我无法在doc中找到任何模块来生成报告。 Actually I'm actual task is to generate the report in Doc only, but as I'm not able to find a module to work on it, I opt for PDF. 实际上,我的实际任务是仅在Doc中生成报告,但是由于无法找到要处理的模块,因此我选择使用PDF。 I'm using “Report Lab” module, but I'm finding some limitation in that. 我正在使用“报告实验室”模块,但是在此方面我发现了一些限制。 It write anything based on co-ordinate system. 它根据坐标系写任何东西。 The problem I'm facing with that the report is usually a string, whose length is not limited, so sometime it goes beyond the canvas( Pdf Page). 我面临的问题是该报告通常是一个字符串,其长度不受限制,因此有时它超出了canvas(Pdf Page)。 Also there is not functionality I guess to do format font with Bold, Italics and Underline. 我猜也没有使用粗体,斜体和下划线做格式字体的功能。

If you know any module to generate report in PDF or Doc, please let me know. 如果您知道用于生成PDF或Doc报告的任何模块,请告诉我。 My requirement is: 我的要求是:

  1. Able to add an image at an header. 能够在标题处添加图像。
  2. Change fonts and other properties, like Bold, Italics, and Underline 更改字体和其他属性,例如粗体,斜体和下划线
  3. Able to draw basic shape like line 能够画出基本形状的线条
  4. Write string, as a statement, as we are able to do with able to write into txt file using python(not on co-ordinate system basis) 作为声明,写入字符串,就像我们能够使用python写入txt文件一样(不基于坐标系)

If you can express your document (including formatting and layout) using HTML, then use xhtml2pdf . 如果可以使用HTML表示文档(包括格式和布局),请使用xhtml2pdf As the name suggests, it will take some HTML document and convert it to PDF preserving the layout and most other design elements. 顾名思义,它将需要一些HTML文档并将其转换为PDF,从而保留布局和大多数其他设计元素。

If you still want to create a doc file, this question has some excellent suggestions. 如果您仍要创建doc文件,则此问题有一些很好的建议。

I should point out you can do all the stuff you want in ReportLab by using the supporting PLATYPUS module. 我应该指出,通过使用支持的PLATYPUS模块,您可以在ReportLab中完成所有您想做的事情。 It lets you easily build documents out of objects in code. 它使您可以轻松地从代码中的对象构建文档。 Alternatively, there is RML, a ReportLab way of building documents from an HTML-like markup language. 另外,还有RML,这是一种ReportLab方法,可通过类似HTML的标记语言构建文档。

您也可以尝试生成LaTeX代码,然后将其编译为PDF。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM