Hello,
I noticed that first and subsequent pages have different top margins. Difference is about 2mm. I am not sure if this is bug or something else.
Below is reproducible test case and PDF created with that script is in attachment test-page-top-margin.pdf
from weasyprint import HTML
main_html = """<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<style>
@page {
margin: 10mm;
size: A4 landscape;
}
.page-fp__header {
height: 80mm;
border: 1px solid #000;
page-break-before: always;
}
</style>
</head>
<body>
<div class="page-fp__header">
CONTENT 1
</div>
<div class="page-fp__header">
CONTENT 2
</div>
<div class="page-fp__header">
CONTENT 4
</div>
</body>
</html>
"""
if __name__ == "__main__":
HTML(string=main_html).write_pdf("test-page-top-margin.pdf")
It's the <body> having a (default) margin of 8 pixels. The top and bottom margins are suppressed when a box is split across pages.
You can either give the body a margin: 0 or (to sustain the margins on each page) a box-decoration-break: clone
Thanks and sorry for the noise.
Most helpful comment
It's the
<body>having a (default) margin of 8 pixels. The top and bottom margins are suppressed when a box is split across pages.You can either give the body a
margin: 0or (to sustain the margins on each page) abox-decoration-break: clone