Skip to content

Commit a7353c2

Browse files
author
Timothy MacDonald
committed
refactor: worked around bug for weasyprint based pdf generation
Signed-off-by: Timothy MacDonald <[email protected]>
1 parent 775ae20 commit a7353c2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lw_report_gen.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def main():
7070
alerts_end_time=pre_processed_args['alerts_end_time'],
7171
custom_logo=custom_logo,
7272
pagesize='a2',
73+
pdf=True,
7374
)
7475

7576
except Exception as e:
@@ -101,8 +102,11 @@ def main():
101102
try:
102103
from weasyprint import HTML, CSS
103104
from weasyprint.text.fonts import FontConfiguration
105+
import logging as log
106+
weasyprint_log = log.getLogger('weasyprint')
107+
weasyprint_log.addHandler(log.FileHandler('weasyprint.log'))
104108
font_config = FontConfiguration()
105-
html = HTML(string=report)
109+
html = HTML(string=report, base_url=basedir)
106110
html.write_pdf(report_file_name, font_config=font_config)
107111
except Exception as e:
108112
logger.error(f'Failed writing report file {report_file_name}: {str(e)}')

templates/csa_detailed_report.jinja2

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
size: {{pagesize}} landscape;
2626
}
2727
{% endif %}
28+
img {visibility: visible !important;}
2829
table {transform: scale(1);}
2930
td, th {
3031
max-width: 150px;
@@ -33,7 +34,6 @@
3334
p {break-inside: avoid;}
3435
div {break-inside: avoid;}
3536
.pagebreak { page-break-after: always; clear: both;}
36-
3737
}
3838
3939
@@ -102,6 +102,12 @@
102102
margin-top: 1.5rem;
103103
}
104104
105+
.promographicpdf img {
106+
display: block;
107+
margin: auto;
108+
width: 90%;
109+
}
110+
105111
.promographic {
106112
display: flex;
107113
justify-content: center;
@@ -403,12 +409,19 @@
403409
{{ summary_data | join(', ') }}
404410
</blockquote>
405411

412+
{% if pdf %}
413+
<div class="promographicpdf">
414+
{% if polygraph_graphic_html %}
415+
{{ polygraph_graphic_html | safe }}
416+
{% endif %}
417+
</div>
418+
{% else %}
406419
<div class="promographic">
407420
{% if polygraph_graphic_html %}
408421
{{ polygraph_graphic_html | safe }}
409422
{% endif %}
410423
</div>
411-
424+
{% endif %}
412425
</div>
413426

414427
<div class="section-two">

0 commit comments

Comments
 (0)