【问题标题】:Printing page numbers using Pisa使用 Pisa 打印页码
【发布时间】:2011-12-21 07:09:53
【问题描述】:

我在我的 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 %}

任何帮助将不胜感激。

【问题讨论】:

    标签: python html django pdf pisa


    【解决方案1】:

    这个链接怎么说:

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

    我遇到的一个问题是在我的页面中添加一个静态页脚,其中包含一个&lt;pdf:pagenumber /&gt; 标签,并且应该在生成的 PDF 的每一页底部显示当前页码。问题是,每个页面都只显示数字 0。解决方案非常简单,但我只能在研究 pisa 源代码后弄清楚:你只能在段落内使用标签,而不是(因为我做了)例如在一张桌子里面。即使表格内的段落也不起作用。它必须是顶级段落。

    编辑

    试试这个:

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

    【讨论】:

    • 好的,所以我在我的 html 上尝试了这个,它打印了&lt;p&gt;&lt;pdf:pagenumber /&gt;&lt;/p&gt;,但仍然没有任何显示?
    • 你是如何生成你的 pdf 的?
    • 我没有看到你在使用

      并记住链接:“你只能在段落中使用标签,而不是(就像我一样) 例如在表格内。即使表格内的段落也不起作用。它必须是顶级段落。"
    • 是的,对不起,我忘了包括那个......它仍然不起作用
    • 您确定标签 不在表格内吗?
    【解决方案2】:

    这对我有用,您需要将其用于 A3 尺寸

    @page{
            size: A3;
            margin: 1cm;
    
          @frame footer_frame {           /* Another static Frame */
            -pdf-frame-content: footer_content;
            left: 400pt; top: 1170pt; height: 20pt;
            
        }
        }
    

    你必须放在上面的桌子上

    <div id="footer_content"> Page <pdf:pagenumber>
    of <pdf:pagecount> </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 2011-12-04
      • 2011-11-16
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      相关资源
      最近更新 更多