Django-easy-pdf,文档每一页上的标头 [英] Django-easy-pdf, header on every page of the document

查看:94
本文介绍了Django-easy-pdf,文档每一页上的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些数据导出为PDF文件.我正在使用:

I am trying to export some data in a PDF file. I am using:

  • Django 1.9.12
  • django-easy-pdf 0.1.0
  • Python 2.7

导出工作正常,并且一切正常(我的观点没有问题),但是我正在努力将页面标题添加到文档的每个页面中.

The export works fine and all (no problem with my view) but I am struggling with adding a page header into every page of the document.

目前,我只能在第一页上进行渲染.我在页脚上没有这样的问题,它可以正确显示在每一页上.

At this point I can only render it on the first page. I have no such problem with the footer, it renders properly on every page.

我的模板如下:

{% extends "easy_pdf/base.html" %}

{% block extra_style %}
<style type="text/css">

    @page {
        size: landscape;
        margin-left: 1cm;
        margin-right: 1cm;
        margin-top: 1.5cm;
        margin-bottom: 2cm;

        @frame footer {
            -pdf-frame-content: page-footer;
            bottom: 0cm;
            margin-left: 1cm;
            margin-right: 1cm;
            height: 2cm;
        }
    }

</style>
{% endblock %}

{% block page_header %}
    {% include "document_head.html" %}
{% endblock %}

{% block content %}
    {% include "main_table.html" %}
{% endblock %}

{% block page_foot %}
    {% include "document_foot.html" %}
{% endblock %}

不包含的情况下执行块操作没有区别.

Doing the blocks without include makes no difference.

我已经根据自己的需要(页面和页脚)从 base.html 重写了一些基本样式.

I have rewritten some base styling from base.html according to my needs (page and footer).

我不确定我是否正确理解标题的功能,但我认为应该在每个页面上呈现该标题(类似于MS Word标题),因为标题不等于标题.我的理解是错误的,因为必须有另一种方法可以在每个页面上呈现页眉.

I am not sure if I understand the functionality of the header properly but in my opinion it should be rendered on every page (similar to MS Word headers), because header does not equal title. If my understaning is wrong than there has to be another way to render a header on every page.

我的PDF内容是动态的,其长度无法预测.

The content of my PDF is dynamic and it's length can not be predicted.

我已阅读文档,但未能找到解决方案问题,我在这里也没有找到任何解决方案.

I have read the documentation and I have failed in finding the solution to my problem and I haven't found any solution here either.

请注意,我以横向方向呈现PDF.

Please also note that I render my PDF in landscape orientation.

感谢您的帮助和建议.

推荐答案

找到了解决方案,如果有人发现它有用,我将在此处发布.

Found a solution and I shall post it here if anyone else finds it usefull.

原来,我不得不完全重写base.html并从其扩展.因此,我的 new_base.html 如下:

It turned out that I had to completly rewrite the base.html and extend from it. So my new_base.html is as follows:

<!DOCTYPE html>
<html>
<head>

    {% block style_base %}
        {% block layout_style %}
            <style type="text/css">

            </style>
        {%endblock%}
        {% block extra_style %}{% endblock %}
    {% endblock %}

</head>
<body>

    <div id="page-header">
        {%block page_header%}
        {%endblock%}
    </div>

    <div>
        {%block content%}
        {%endblock%}
    </div>

    <div id="page-footer">
        {%block page_foot%}
        {%endblock%}
    </div>
</body>

在扩展new_base.html的模板中,我添加了以下几行:

And in my template which extends new_base.html I have added the following lines:

@frame header {
    -pdf-frame-content: page-header;
    top: 0cm;
    margin-top: 0.5cm;
    margin-bottom: 0.5cm;
    margin-left: 1cm;
    margin-right: 1cm;
    height: 5cm;
}

现在,这将在文档的每个页面上呈现页面标题.

这篇关于Django-easy-pdf,文档每一页上的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆