【问题标题】:how to generate and print documents (python)如何生成和打印文档(python)
【发布时间】:2011-10-20 04:57:12
【问题描述】:

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

用户填写打印表格(选择客户、月份、他/她需要的 4 种文件中的每一种文件的份数)并点击打印按钮。

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

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

要求:

  • 能够编辑结果(需要文字格式)
  • 分页符(新页面上的每个文档)
  • 表格,不是很简单,看invoice tpl例子:
  • 字体大小和样式(例如粗体)
  • 保存文本位置

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

附言更好地使用 python 但它并不重要,我可以使用 java/perl/ruby/php/bash/etc.. 并安装任何新的 Ubuntu 兼容包...

【问题讨论】:

    标签: python printing


    【解决方案1】:

    如果不是绝对需要使用模板,或者如果您愿意使用代码重新创建模板,请使用reportlab 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

    【讨论】:

    • 以后可以手动编辑这份 pdf 报告吗? (例如,更改此表中的值)
    猜你喜欢
    • 2011-01-21
    • 2016-01-03
    • 1970-01-01
    • 2014-07-02
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    相关资源
    最近更新 更多