gpt4 book ai didi

Django-easy-pdf,文档每一页上的标题

转载 作者:行者123 更新时间:2023-12-02 00:48:26 26 4
gpt4 key购买 nike

我正在尝试将一些数据导出到 PDF 文件中。我正在使用:

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

导出工作正常(我的观点没有问题)但我正在努力将页眉添加到文档的每一页。

此时我只能在第一页上渲染它。我对页脚没有这样的问题,它在每一页上都能正确呈现。

我的模板如下:

{% 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 %}

不包含的情况下执行 block 没有任何区别。

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

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

我的 PDF 的内容是动态的,它的长度无法预测。

我已阅读 documentation我没有找到解决问题的方法,我也没有在这里找到任何解决方法。

另请注意,我以横向方向呈现我的 PDF。

感谢您的帮助和建议。

最佳答案

找到了一个解决方案,如果有人觉得有用,我会把它贴在这里。

事实证明,我必须完全重写 base.html 并从中扩展。所以我的new_base.html如下:

<!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 的模板中,我添加了以下几行:

@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,文档每一页上的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41961365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com