django - Django PDFTemplateView (easy_pdf) tidying up a report with page breaks
问题描述
I saw where I can Have a page break in a easy pdf html template saying
<p class="pb"></p>
That is great, but I am trying to run a report where it page breaks and puts a table header every so many lines, with special consideration for the first page. Is there anyway to do this?
This is the view I am calling my html from:
class InvoiceReportIDPDF(PDFTemplateView):
#template_name = 'ipaswdb/provider/report/provider_profile.html'
template_name = 'ipaswdb/invoice/report/invoice_report_pdf.html'
def get_context_data(self, **kwargs):
context = super(InvoiceReportIDPDF, self).get_context_data(pagesize='LetterSize',title='Invoice',**kwargs)
#print "provider id: ", kwargs['pk']
self.download_filename = 'invoice-report-' + kwargs['pk'] + '.pdf'
res = build_invoice_printout_models(kwargs['pk'])
#res = build_invoice_printout_models('all')
return context
So I can print this invoice but the line items just run from one page to the next with no nice header at the top of the next page (for when same invoice)...
I can't use variables in the html page to count using the template and I thought Id get slick and when I build the items I send to the webpage to put in a field for a page break.
So when I build my object I send to the view context I have like:
invoiceItem['pagebreak'] = None
if lineCount > xmany:
invoiceItem['pagebreak'] = 'YES'
Then in the html:
{% if invoice.items %}
{% for item in invoice.items %}
<tr>
<td> {{ item.name}} - {{ item.provspecialty }} </td>
<td> Current Dues </td>
<td> </td>
<td> ${{ item.dues }} </td>
</tr>
<tr>
<td></td>
<td> {{ item.desc }} </td>
<td> ${{ item.adjustments}}</td>
<td></td>
</tr>
{% if item.pagebreak %}
<p class="pb"> </p> <!-- this didn't work right at all -->
<!-- just sent a bunch of blank lines then 5 pages down tried to work-->
{% endif %}
{% endfor %}
{% endif %}
I wish it just 'knew' where the bottom of the page was to make the break and add a new header...
解决方案
推荐阅读
- github - 从 bitbucket 克隆 repo 时出现 Google Cloud Platform 错误
- c# - 如何在 XamarinForms 中获取设备时间格式
- ios - 屏幕关闭/设备在 iOS 中锁定时计时器不运行
- imagemagick - ImageMagick 在玻璃上的雕刻效果
- php - 如何用特殊符号(。)替换字符串中的单词?
- java - 自定义标记位图错误 无法解码图像。提供的图像必须是位图
- vba - 作为计划任务运行时从 ms 访问保存图形图像
- unit-testing - 在 Visual Studio 和 MSTest 中使用测试资源管理器执行自动化测试的问题
- java - 如何在 Map 中查找键的重复值
- intel-pin - 如何在指定时间后终止 PINTool