Reputation: 376
I am generating a PDF with running headers using FlyingSaucer 9 with the following HTML template:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@page {
size: 793px 1122px;
border: 1px solid navy;
margin: 25px 35px 53px 35px;
padding: 0; /*Does not work*/
@top-center {content:element(header);}
}
#header {
position: running(header);
border: 1px solid red;
}
</style>
<title></title>
</head>
<body>
<div id="header">Test header</div>
Lorem ipsum dolor sit amet, [and some other lenghty text ...]
</body>
</html>
The problem that I am facing is that there is a "default padding" for the generated PDF. I have added a border: 1px solid navy to the @page selector for the "default padding" to be visible. The problem is that this padding is only present in the top of the first page of the PDF but it is missing in the second, third and other pages. This is causing a gap between my header (marked with a red border) and the rest of the body but only on the first page of the PDF.
Here is the first page of the generated PDF with a visible default top padding:
And here is the second page with no top padding at all (this happens to all pages except the first one):
I've tried adding @page { padding: 0; } but it doesn't work. Does anyone have an idea how to remove the "default padding" of the @page element or how I can make the gap of my header go away for the first page of the PDF?
Upvotes: 1
Views: 2234
Reputation: 9356
You can correct the issue by setting the margin to 0 for the body:
body{margin:0}
Upvotes: 2