我正在用python2.7和Flask开发一个web应用程序。我使用xhtml2pdf生成一个基于Jinja2模板的pdf。 我想把一个图像放在模板的页眉框上,但它只显示在第一页上。 我试着用文本来做,结果很管用,页眉显示在所有页面上。在
以下是视图代码:
@report.route('/commissionist/<period>/<commissionist_id>')
@login_required
def commissionist_report(period, commissionist_id):
period_d = periods.Period(datetime.fromtimestamp(mktime(strptime(period, '%m-%Y'))))
carga = load_model.get_commissionist_load(period_d, commissionist_id)
resp = create_pdf(render_template('report/report.html', commissionist_load=carga, period=period, period_datetime=period_d.to_datetime()))
response = make_response(resp)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = 'inline; filename=Informe '+carga.commissionist.name+'.pdf'
return response
以下是create_pdf函数:
^{pr2}$以下是模板(重要部分):
<!DOCTYPE html>
<html>
<head>
<title>Informe</title>
{% block extra_css %}
<style>
@page {
size: letter portrait;
@frame header_frame { /* Static Frame */
-pdf-frame-content: header_content;
left: 50pt; width: 512pt; top: 50pt; height: 50pt;
}
@frame content_frame { /* Content Frame */
left: 50pt; width: 512pt; top: 110pt; height: 632pt;
}
@frame footer_frame { /* Another static Frame */
-pdf-frame-content: footer_content;
left: 50pt; width: 512pt; top: 772pt; height: 20pt;
}
}
</style>
{% endblock %}
</head>
<body>
{% block body %}
<div id="header_content">
<img src="path\to\file.png" width="25%">
</div>
<div id="footer_content">Página <pdf:pagenumber/>
de <pdf:pagecount/>
</div>
<!--The rest of the html-->
{% endblock %}
</body>
</html>
希望你能帮助我。谢谢。在
目前没有回答
相关问题 更多 >
编程相关推荐