fix(#180): @page-Größe in pt statt px für korrekte PNG-Pixel-Dimensionen

WeasyPrint konvertiert CSS-px zu PDF-pt mit 96/72=0.75-Faktor:
1080px CSS-Page → 810pt PDF-Page → 810px PNG (bei zoom=1).
Mit 'size: 1080pt 1080pt' wird die PDF-Page direkt 1080pt
und PyMuPDF rendert 1080×1080px wie erwartet.
This commit is contained in:
Dotty Dotter 2026-05-07 08:04:56 +02:00
parent 52ff36a136
commit d8999f8a64

View File

@ -3459,7 +3459,11 @@ async def _render_scorecard_pdf(
width=width, height=height, width=width, height=height,
) )
page_size_css = f"@page {{ size: {width}px {height}px; margin: 0; }}" # `size: NNNpt` → PDF-Page hat exakt N×M Punkte. PyMuPDF rendert
# bei zoom=1 dann 1 PDF-Punkt = 1 PNG-Pixel. CSS-Pixel werden
# aber auch in pt umgerechnet (96dpi → 72dpi → ×0.75) — daher
# konvertiere pt→css-px so, dass die Inhalts-Layouts passen.
page_size_css = f"@page {{ size: {width}pt {height}pt; margin: 0; }}"
pdf = HTML(string=html_content).write_pdf(stylesheets=[CSS(string=page_size_css)]) pdf = HTML(string=html_content).write_pdf(stylesheets=[CSS(string=page_size_css)])
safe = drucksache.replace("/", "-") safe = drucksache.replace("/", "-")
return pdf, width, height, f"scorecard-{safe}-{format}" return pdf, width, height, f"scorecard-{safe}-{format}"