首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何生成和打印文档(python)

问如何生成和打印文档(python)
EN

Stack Overflow用户
提问于 2011-10-20 04:57:12
回答 1查看 9.9K关注 0票数 5

我需要允许用户编辑和打印与客户相关的文件(发票和其他)。

用户填写打印表单(选择客户端,每月,他/她需要的4种文档中每种文档的拷贝数),然后单击打印按钮。

接下来,我的系统应该做(算法):

代码语言:javascript
复制
result = create new word-friendly file  # because user may manually edit it later

for client in form_clients:

    snapshot = select row in snapshots table 
               where client == client and month == form_month

    document1 = generate_from_template(snapshot, tpl1.docx)
    for 1 to form_how_much_copies_of_1_type_of_document_he_or_she_needs:
        result += document1

    document2 = generate_from_template(snapshot, tpl2.docx)
    for 1 to form_how_much_copies_of_2_type_of_document_he_or_she_needs:
        result += document2

    document3 = generate_from_template(snapshot, tpl3.docx)
    for 1 to form_how_much_copies_of_3_type_of_document_he_or_she_needs:
        result += document3

    document4 = generate_from_template(snapshot, tpl4.docx)
    for 1 to form_how_much_copies_of_4_type_of_document_he_or_she_needs:
        result += document4

print result

要求:

  • 编辑结果的能力(需要文字格式)
  • 分页(新页上的每个文档)
  • 表,不是很简单,请看示例:

​

  • 字体大小和样式(例如粗体)
  • 保存文本位置

我的问题是如何生成这个文件(结果)?有https://github.com/mikemaccana/python-docx项目,但不确定它是否可以使用模板(或者至少生成我需要的表).或者我可以将我的所有.docx模板保存为html,并将它们作为普通的django模板使用,但不确定如何将它们合并到一个文档中并创建分页符.或者我应该考虑另一种文字兼容的文件格式?

附注:最好使用python,但它并不重要,我可以使用java/perl/ruby/php/bash/等等。并安装任何与Ubuntu兼容的新软件包.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-20 07:33:15

如果使用模板不是绝对必要的,或者如果您愿意用代码重新创建模板,请使用报告室 for python生成一个PDF,然后打印它。

请参阅关于如何制作表的示例:http://www.blog.pythonlibrary.org/2010/09/21/reportlab-tables-creating-tables-in-pdfs-with-python/

还请查看此发票示例:https://github.com/radzhome/fedex-commercial-invoice

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7831328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档