使用比萨打印页码

时间:2011-11-03 15:24:31

标签: python html django pdf pisa

我在我的django项目中使用pisa,使我的html生成在PDF上用于报告功能。我的一些报告变得相当大,我注意到它上面没有任何页码。有谁知道如何在打印的PDF报告中显示页码?

修改

这是我如何生成PDF

if request.POST.has_key('print_report_submit'):
            context['show_report'] = True
            context['mb_logo'] = os.path.join(os.path.dirname(__file__), "../../../media/images/mb_logo.jpg")
            html = render_to_string('reports/fam_maturity_print.html', RequestContext(request,context))
            result = StringIO.StringIO()
            pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
            response = HttpResponse(result.getvalue(), mimetype='application/pdf')
            response['Content-Disposition'] = 'attachment; filename=family_maturity-statement.pdf'
            return response

HTML

{% if show_report %}

<table width="100%">

    <tr>
        <td colspan="2" align="center" width="400px">
            <h1 class="title">Family Maturities by Year</h1>
            <br/><br/>
        </td>
    </tr>
    <tr>
        <td width="500px">
            <img src="{{ mb_logo }}"/>
        <td>                            <p>
              <img style="max-height: 60px; max-width:60px;" src="{{ check_image }}"/>
          </p>
    </tr>
</table>
    <br/>
    <br/>



   <hr class="report_hr1"/>
   <h2 class="state_head" style="font-size: 16px;">Statement Information As of {{ statement_date|date:"F d, Y" }}</h2>
<hr class="report_hr1"/>

    <table>

    {% for plan_dict in plan_list %}
        <hr class="report_hr2"/>
        <table>
        <tr>
            <td><strong>Plan Holder: </strong></td><td>{{ plan_dict.plan.get_primary_owner.member.client}}</td>
            <td><strong>Joint Owner(s): </strong></td>
            <td>
                {% for member in plan_dict.plan.planmember_set.all %}
                    {% ifnotequal member.ownership_type.code "primary" %}
                        {{ member }}
                    {% endifnotequal %}
                {% endfor %}
            </td>
        </tr>
        <tr>
            <td><strong>Plan ID: </strong></td><td>{{ plan_dict.plan.id }}</td>
        </tr>
        <tr>
            <td><strong>Plan type: </strong></td><td>{{ plan_dict.plan.plan_type }}</td>
        </tr>
        </table>
        <hr class="report_hr2"/>
        {#      This is the table for the current year's maturities      #}
        {% if plan_dict.investment %}
        <table>
            <td colspan="2"><h3>{{ cur_year }}</h3></td>
            <tr>
                <th>Financial Institution</th>
                <th>Type</th>
                <th>Principal</th>
                <th>Maturity</th>
            </tr>
            {% for i in plan_dict.investment %}
            <tr>
                <td>{{ i.financial_institution.abbr }}</td>
                <td>{{ i.product.code }}</td>
                <td>${{ i.amount|intcomma }}</td>
                <td>${{ i.maturity_amount|intcomma }}</td>
            </tr>
            {% endfor %}
            <tr>
                    <td><strong>Total for {{ cur_year }}</strong></td>
                    <td></td>
                    <td><strong>${{ plan_dict.total|intcomma }}</strong></td>
                    <td><strong>${{ plan_dict.total_m|intcomma }}</strong></td>
                </tr>
        </table>
        {% endif %}
        <div id="holding_table" align="center">
               <h3>Holding Totals with Each Company</h3>
               <table>
                    <tr>
                        <td style="font-weight: bold;">Financial Institution</td>
                        <td style="font-weight: bold;">Total</td>
                    </tr>
               {% for l in plan_dict.total_list %}
                   {% if l.maturity_amount__sum != None %}
                       <tr>
                        <td>{{ l.financial_institution__abbr }}</td>
                        <td>${{ l.maturity_amount__sum|intcomma }}</td>
                    </tr>
                   {% endif %}
               {% endfor %}
                    <tr>
                        <td style="font-weight: bold;">Total Non-Fund Holdings for this plan</td>
                        <td style="font-weight: bold;">${{ plan_dict.grand|intcomma }}</td>
                    </tr>
               </table>
                <span class="disclaimer_span">This report has been prepared from data believed to be reliable but no
                        representation is made as to accuracy or completeness.</span>
        </div>
        <br/>
        <br/>

    {% endfor %}
    </table>
{% endif %}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

如何在此链接中说:

http://www.arnebrodowski.de/blog/501-Pisa-and-Reportlab-pitfalls.html

  

我遇到的一个问题是在我的网页中添加了一个静态页脚,其中包含<pdf:pagenumber />标记,并且应该在生成的PDF的每个页面底部显示当前页面编号。问题是,每个页面只显示数字0.解决方案非常简单,但我只能在研究比萨源代码后弄明白:你只能在一个段落中使用标签,而不是(因为我例如,在一张桌子里面。甚至表格中的parapgraph也行不通。它必须是顶级段落。

修改

试试这个:

<div>
   <pdf:pagenumber />
</div>