多页呈现时第一页空白?

2024-04-20 00:08:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pisa从html打印到pdf。我有个问题。 如果数据量少,则打印在第一页。若数据量多,他打印在下一页,但第一页是空的。 你觉得怎么样? 请帮帮我

table {
        -pdf-keep-with-next: true;
    }

    @page {
        size: letter portrait;
        margin-right: 30pt;
        margin-left: 30pt;
    }

    @frame content_frame {
        left: 50pt;
        width: 512pt;
        top: 50pt;
        height: 692pt;
    }



context = Context(context_dict)
        html = template.render(context)
        result = StringIO.StringIO()
        pisa.CreatePDF(html.encode("UTF-8"), result, encoding='UTF-8', link_callback=self.fetch_resources)
        response = HttpResponse(result.getvalue(), mimetype='application/pdf')
        response['Content-Disposition'] = 'attachment; filename=report-%s-%s.pdf' % (start_date, end_date)
        RequestContext(request)

<tbody>
     <tr class="text-center">
        <td>{% trans "Date" %}</td>
        <td class="padding-top-5">
            <p class="text-center"> {% trans "Journal" %} </p>
            <p style="margin: 0 5pt;">{% trans "history, status, diagnosis and treatment for the treatment of recurrent disease" %}</p>
        </td>
        <td>{% trans "Doctor" %}</td>
    </tr>
    {% for reception in receptions %}
        <tr>
            <td class="text-center" style="width: 30%; vertical-align: top">
                <p class="separator">&nbsp;</p>
                {{ reception.date_created|date:"d F Y" }}
            </td>
            <td>
                <div style="padding: 5px">
                    {% if reception.result|length_is:0 or reception.result == None %}
                    {% else %}
                        {{ reception.result|linebreaks }}
                    {% endif %}
                </div>

            <td style="vertical-align: top; width: 30%">
                <p class="separator">&nbsp;</p>
                &nbsp;{{ reception.doctor.doctor_name }}
            </td>
        </tr>

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

Tags: textmargintransdatepdfstyletophtml