【发布时间】:2020-05-29 00:24:42
【问题描述】:
要从 html 创建 pdf,我使用 easy_pdf 连接到 xhtml2pdf。
小例子:
在 view.py 中
from easy_pdf.rendering import render_to_pdf_response
context = dict({'user_company': 'test'})
template_name = "pdf_template.html"
return render_to_pdf_response(request, template_name, context)
html模板:
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<style>
* {
margin: 0 !important;
padding: 0 !important;
}
</style>
</head>
<body>
{{user_company}}
<img src="/static/some_image.png" height="1000" width="1000">
</body>
</html>
图像和所有元素都放在边距内:
我尝试在side_packages/easy_pdf/templates/easy_pdf/base.html 中更改并添加一些边距选项:github link
<style type="text/css">
@page {
// added
margin: 0 !important;
* {
margin: 0 !important;
padding: 0 !important;
}
body {
margin: 0 !important;
padding: 0 !important;
}
@frame {
margin: 0 !important;
}
// changed
size: {{ pagesize|default:"A4" }};
margin-left: 0;
margin-right: 0;
margin-top: 0;
margin-bottom: 0;
@frame header {
-pdf-frame-content: page-header;
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
}
@frame footer {
-pdf-frame-content: page-footer;
bottom: 0;
margin-left: 0;
margin-right: 0;
height: 0;
}
}
</style>
但没有效果
问题
在哪里添加或更改 css 选项以从 pdf 中删除边距?
【问题讨论】:
标签: python css django python-3.x django-templates