- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在使用reportlab生成的pdf中的表格后插入分页符,我正在使用以下函数生成pdf:
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), dest=result, link_callback=fetch_resources)
if not pdf.err:
return result.getvalue()
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
def fetch_resources(uri, rel):
return os.path.join(MEDIA_ROOT, uri.replace(MEDIA_URL, ""))
@login_required(login_url=reverse('accounts:login_box'))
def quote_pdf(request, quote_id):
data_pdf = {}
quote = get_object_or_404(Quote, id=quote_id)
data_pdf['pagesize'] = 'letter'
data_pdf['quote'] = quote
pdf = render_to_pdf('rents/quote_pdf.html', data_pdf)
return HttpResponse(pdf, mimetype='application/pdf')
{% load humanize compress verbatim %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Cotización No. {{ quote.id }} Flasherz.co/alquiler</title>
<style type="text/css">
@page {
size: {{ pagesize }};
margin: 1cm;
@frame footer {
-pdf-frame-content: footerContent;
bottom: 0cm;
margin-left: 0cm;
margin-right: 0cm;
height: 0cm;
}
}
</style>
<style type="text/css">
body {
font-size: 12px;
line-height: 13px;
}
div#pdf-header {
display: block;
}
div#pdf-header h2 {
display: block;
text-align: center;
font-weight: normal;
line-height: 35px;
font-size: 18px;
}
div#pdf-quote-info {
display: block;
margin-bottom: 20px;
}
p {
margin: 0;
}
table {
border-top: 1px solid #eee;
}
table td, table th {
border-right: 1px solid #eee;
border-bottom: 1px solid #eee;
padding: 5px;
border-left: 1px solid #eee;
}
table .price {
text-align: right;
}
table th {
padding: 5px 0;
font-size: 13px;
text-transform: uppercase;
color: black;
text-align: left;
background-color: #eee;
padding-left: 5px;
}
table p.description {
color: #555;
font-size: 11px;
}
table#quote-info {
border: none;
}
table#quote-info td, table#quote-info th {
border: none;
padding: 0;
}
table td.quantity {
text-align: center;
}
</style>
</head>
<body>
<div id="pdf-header">
<div style="width: 100%; text-align: center;">
<img src="{{ STATIC_URL }}img/quotes-logo.jpeg" alt="Flasherz.co Alquiler" width="600" height="126" />
<div style="display: block; text-align: center; margin: 10px 0;">
<h2>Cotización No. {{ quote.id }}, {{ quote.client_name }}</h2>
</div>
</div>
</div>
<div id="pdf-quote-info">
<table id="quote-info" width="70%" border="none" cellpadding="3" cellspacing="0">
<tr>
<td width="25%">Fecha:</td>
<td width="75%">{{ quote.created|date:'l j' }} de {{ quote.created|date:'F' }} de {{ quote.created|date:'Y' }}</td>
</tr>
{% if quote.client_name %}
<tr>
<td>Cliente:</td>
<td>{{ quote.client_name }}</td>
</tr>
{% endif %}
{% if quote.client_email %}
<tr>
<td>Correo:</td>
<td>{{ quote.client_email }}</td>
</tr>
{% endif %}
{% if quote.client_address %}
<tr>
<td>Dirección:</td>
<td>{{ quote.client_address }}</td>
</tr>
{% endif %}
{% if quote.client_phone %}
<tr>
<td>Teléfono:</td>
<td>{{ quote.client_phone }}</td>
</tr>
{% endif %}
<tr>
<td>Cantidad de días:</td>
<td>{{ quote.rental_days }}</td>
</tr>
</table>
</div>
</div>
<div id="pdf-quote-table">
<table id="quote-table" cellpadding="0" cellspacing="0" width="100%">
{% for category in quote.categories.all %}
<tbody>
<tr>
<th colspan="4" class="category-header">{{ category.category.name }}</th>
</tr>
{% for item in category.items.all %}
<tr>
<td class="quantity" width="10%">
<p>{{ item.quantity }}</p>
</td>
<td class="name" width="50%">
<p class="name">{{ item.name }}</p>
{% if item.content %}<p class="description">{{ item.content }}</p>{% endif %}
</td>
<td class="price" width="20%">
<p>${{ item.price|intcomma }}</p>
</td>
<td class="price total-price" width="20%">
<p>${{ item.total_price|intcomma }}</p>
</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
<tbody id="others">
<tr>
<th colspan="4" class="category-header">Seguro del 10%</th>
</tr>
<tr>
<td class="quantity"></td>
<td class="name">Seguro 10%</td>
<td class="price"></td>
<td class="price total-price">
<p>${{ quote.get_insurance_price|intcomma }}</p>
</td>
</tr>
</tbody>
{% if quote.discount %}
<tbody id="others">
<tr>
<th colspan="4" class="category-header">Descuento</th>
</tr>
<tr>
<td class="quantity">
</td>
<td class="name">Descuento</td>
<td class="price"></td>
<td class="price total-price">
<p>${{ quote.discount|intcomma }}</p>
</td>
</tr>
</tbody>
{% endif %}
<tbody id="totals">
<tr>
<th colspan="4" class="category-header">Total</th>
</tr>
<tr>
<td class="fake" colspan="2"></td>
<td class="name">Subtotal</td>
<td class="price">
<p>${{ quote.get_subtotal|intcomma }}</p>
</td>
</tr>
<tr>
<td class="fake" colspan="2"></td>
<td class="name">Total días</td>
<td class="price">
<p>${{ quote.get_total_days|intcomma }}</p>
</td>
</tr>
<tr>
<td class="fake" colspan="2"></td>
<td class="name">Total</td>
<td class="price">
<p><strong>${{ quote.get_total|intcomma }}</strong></p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
最佳答案
我找到了正确的方法,我需要在我的 pdf 中插入一些特定的样式
<style type="text/css">
@page {
size: {{ pagesize }};
margin: 1cm;
@frame footer {
-pdf-frame-content: footerContent;
bottom: 0cm;
margin-left: 0cm;
margin-right: 0cm;
height: 0cm;
}
}
.page-break{
page-break-after: always;
}
</style>
关于Django reportlab 插入分页符 html 端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15306757/
ReportLab 用户指南中说: The colortest.py script in reportlab/demos/colors demonstrates thedifferent ways i
ReportLab 用户指南中说: The colortest.py script in reportlab/demos/colors demonstrates thedifferent ways i
我正在使用 ReportLab VerticalBarChart 生成条形图。我需要其中一个条(每次都是不同的)与其他条的颜色不同,以指定它是“选择”值。 否则,我需要以与其他栏不同的方式标记它。 知
我正在使用 ReportLab 生成 PDF 报告。 我使用了 SimpleDocTemplate 并设置了 pageSize = A5。但是在构建PDF后,当我打开创建的文件时,页面大小为A4。 d
是否可以在段落样式中设置字母/字符间距?我尝试使用spaceShrinkage但这没有任何区别 最佳答案 根据official documentation ,p。 30: The setCharSpa
我的销售订单模板中有以下 rml: [[ repeatIn(o.order_line, 'l') ]] [[ l.name ]] [[
你好, 我正在使用报告实验室生成 pdf。我想绘制一个文本,它是一个 Paragraph,代表一个标题,因此,如果标题比段落的可用长度长,它将在下一行拆分,如果标题太长适合段落的可用宽度和高度,然后调
如何设置表格的左侧位置? response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = '
在报告实验室中 user guide (第 79 页),这是将图像插入表格的方式。 I = Image('../images/replogo.gif') I.drawHeight = 1.25*inc
reportlab文档中有LINEBELOW和LINEABOVE。但我找不到定义右边界或左边界(LINELEFT、LINERIGHT)的方法。 关于如何渲染只有右边框的单元格有什么建议吗? 编辑: 我
有什么方法可以在 reportlab 中获取 Flowable Paragraph 的行数?我有一个很长的字符串,用不同的大小和字体打印。我需要知道要使用 TA_JUSTIFY 对齐打印的整个段落使用
在文档和源代码中,我看到很多对圆角矩形的引用,但是,我似乎无法绘制一个。 我正在绘制一个普通的矩形: canvas.rect(15, 625, 250, 125, fill=0) 我向圆角传递哪些参数
我正在处理发票,我只想在最后一页(也可以是第一页)添加页脚。 由于表的数据是动态的,我无法计算页数。 现在我正在使用 2 个页面模板,第一页(带有 2 个框架和页脚 1)和下一页(带有 1 个框架和页
我知道 LINEABOVE 和 LINEBELOW 样式,我想知道是否有一种方法可以在表格中绘制一条指定宽度的线。 我正在尝试添加一条不“接触”表格边框的线,如果我可以在单元格之间添加一些填充,LIN
我快速浏览了一下网络,但未能找到一种在 Python 中使用 ReportLab 生成 PDF 时设置背景颜色的方法。如何设置背景颜色? 最佳答案 不要使用复杂的方法,而是使用这个简单的技巧: im
我想知道如何将我的脚本保存到桌面。这是我的代码: from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import let
您好,我是报告实验室的新手。我想生成一份包含表格的 pdf 报告。表格中的某些列文本大于列宽,现在我想根据列宽换行文本。 以下是我编写的代码 # Imports from reportlab.pdfg
我正在使用XPreformatted打印一些预格式化的文本,我有一个 换行符的问题。 换行符正确翻译,但另外我得到一个 每行末尾都有“问号”。 这是我的输出: first line? second l
我知道 LINEABOVE 和 LINEBELOW 样式,我想知道是否有一种方法可以在表格中绘制一条指定宽度的线。 我正在尝试添加一条不“接触”表格边框的线,如果我可以在单元格之间添加一些填充,LIN
我快速浏览了一下网络,但未能找到一种在 Python 中使用 ReportLab 生成 PDF 时设置背景颜色的方法。如何设置背景颜色? 最佳答案 不要使用复杂的方法,而是使用这个简单的技巧: im
我是一名优秀的程序员,十分优秀!