CSS 不适用于 xhtml2pdf Django
CSS doesn't work with xhtml2pdf Django
我正在尝试改进由 xhtml2pdf
创建的生成的 PDF,在我的 Django Project
中添加一些 CSS style
。
例如,我想 justify a text block
,但显然它不起作用,我也找不到原因。我正在阅读很多关于这个库的文档,我写了一些 CSS 脚本,但仍然一无所获。
这是我的 HTML 文件:
<html>
<head>
{% load staticfiles %}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" />
<style>
p {text-align: justify;}
</style>
</head>
<font face="Courier New, monospace"
<body>
<logo class="logo">
<img src='/Users/valentinjungbluth/Desktop/Django/Etat_civil/Etat_civil/static/images/logo.png' />
</logo>
<h2 align="center"> <font color="red" size="6"> ACTE DE NAISSANCE <br /> COPIE INTEGRALE </font></align> </h2>
<br></br>
<br></br>
{% block content %}
<h3 align="left"> ACTE DE NAISSANCE N° {{birthcertificate.id}} / {% now "Y" %} {{birthcertificate.firstname}} {{birthcertificate.lastname}}</align> </h3>
<br></br>
<p>Le {{birthcertificate.birthday}} est né, {{birthcertificate.firstname}} {{birthcertificate.lastname}}, du sexe {{birthcertificate.sex}}, <br />
de {{birthcertificate.fk_parent1.firstname}} {{birthcertificate.fk_parent1.lastname}}, né à {{birthcertificate.fk_parent1.birthcity}} ({{birthcertificate.fk_parent1.country}}) le {{birthcertificate.fk_parent1.birthday}}, {{birthcertificate.fk_parent1.job}},<br />
et de {{birthcertificate.fk_parent2.firstname}} {{birthcertificate.fk_parent2.lastname}}, née à {{birthcertificate.fk_parent2.birthcity}} ({{birthcertificate.fk_parent2.country}})<br />
le {{birthcertificate.fk_parent2.birthday}}, {{birthcertificate.fk_parent2.job}}, domiciliés au {{birthcertificate.fk_parent1.adress}}.
</p>
<br></br>
Dressé le {% now "SHORT_DATETIME_FORMAT" %} à ... , lecture faite et invité à lire l'acte, a signé avec Nous, <br /> {{user}}, chevalier de la Légion d'honneur, officier de l'Etat Civil.
<h3> Le {% now "SHORT_DATETIME_FORMAT" %}
<br /> Par la présente, l'Officier d'Etat Civil certifie la conformité de la présente déclaration </h3>
<br></br>
<h3 align ="right"> L'Officier d'Etat Civil </align> </h3>
<h3 align ="right"> Signature et tampon </align> </h3>
{% endblock %}
</font>
</body>
</html>
当我生成 PDF 时,我得到了这个文件:
如您所见,块文本没有对齐。我也试过添加一个background-color
但是总是一样的问题,没有考虑到。
如果你有想法,非常感谢!
编辑:
我找到了答案:句子不够长,不足以证明文本的合理性!
您在 xhtml2pdf 中没有 CSS 属性 "text-align: justify"。
集成了以下属性:
background-color
border-bottom-color, border-bottom-style, border-bottom-width
border-left-color, border-left-style, border-left-width
border-right-color, border-right-style, border-right-width
border-top-color, border-top-style, border-top-width
colordisplay
font-family, font-size, font-style, font-weight
height
line-height, list-style-type
margin-bottom, margin-left, margin-right, margin-top
padding-bottom, padding-left, padding-right, padding-top
page-break-after, page-break-before
size
text-align, text-decoration, text-indent
vertical-align
white-space
width
zoom
我正在尝试改进由 xhtml2pdf
创建的生成的 PDF,在我的 Django Project
中添加一些 CSS style
。
例如,我想 justify a text block
,但显然它不起作用,我也找不到原因。我正在阅读很多关于这个库的文档,我写了一些 CSS 脚本,但仍然一无所获。
这是我的 HTML 文件:
<html>
<head>
{% load staticfiles %}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" />
<style>
p {text-align: justify;}
</style>
</head>
<font face="Courier New, monospace"
<body>
<logo class="logo">
<img src='/Users/valentinjungbluth/Desktop/Django/Etat_civil/Etat_civil/static/images/logo.png' />
</logo>
<h2 align="center"> <font color="red" size="6"> ACTE DE NAISSANCE <br /> COPIE INTEGRALE </font></align> </h2>
<br></br>
<br></br>
{% block content %}
<h3 align="left"> ACTE DE NAISSANCE N° {{birthcertificate.id}} / {% now "Y" %} {{birthcertificate.firstname}} {{birthcertificate.lastname}}</align> </h3>
<br></br>
<p>Le {{birthcertificate.birthday}} est né, {{birthcertificate.firstname}} {{birthcertificate.lastname}}, du sexe {{birthcertificate.sex}}, <br />
de {{birthcertificate.fk_parent1.firstname}} {{birthcertificate.fk_parent1.lastname}}, né à {{birthcertificate.fk_parent1.birthcity}} ({{birthcertificate.fk_parent1.country}}) le {{birthcertificate.fk_parent1.birthday}}, {{birthcertificate.fk_parent1.job}},<br />
et de {{birthcertificate.fk_parent2.firstname}} {{birthcertificate.fk_parent2.lastname}}, née à {{birthcertificate.fk_parent2.birthcity}} ({{birthcertificate.fk_parent2.country}})<br />
le {{birthcertificate.fk_parent2.birthday}}, {{birthcertificate.fk_parent2.job}}, domiciliés au {{birthcertificate.fk_parent1.adress}}.
</p>
<br></br>
Dressé le {% now "SHORT_DATETIME_FORMAT" %} à ... , lecture faite et invité à lire l'acte, a signé avec Nous, <br /> {{user}}, chevalier de la Légion d'honneur, officier de l'Etat Civil.
<h3> Le {% now "SHORT_DATETIME_FORMAT" %}
<br /> Par la présente, l'Officier d'Etat Civil certifie la conformité de la présente déclaration </h3>
<br></br>
<h3 align ="right"> L'Officier d'Etat Civil </align> </h3>
<h3 align ="right"> Signature et tampon </align> </h3>
{% endblock %}
</font>
</body>
</html>
当我生成 PDF 时,我得到了这个文件:
如您所见,块文本没有对齐。我也试过添加一个background-color
但是总是一样的问题,没有考虑到。
如果你有想法,非常感谢!
编辑:
我找到了答案:句子不够长,不足以证明文本的合理性!
您在 xhtml2pdf 中没有 CSS 属性 "text-align: justify"。 集成了以下属性:
background-color
border-bottom-color, border-bottom-style, border-bottom-width
border-left-color, border-left-style, border-left-width
border-right-color, border-right-style, border-right-width
border-top-color, border-top-style, border-top-width
colordisplay
font-family, font-size, font-style, font-weight
height
line-height, list-style-type
margin-bottom, margin-left, margin-right, margin-top
padding-bottom, padding-left, padding-right, padding-top
page-break-after, page-break-before
size
text-align, text-decoration, text-indent
vertical-align
white-space
width
zoom