I’m trying to create an ticket width the dimensions (203mmx82mm). This is in HTML and CSS via python (cgi, jinja2, weasyprint) the template will be converted to an pdf, which the user can download via a button on the website.
The HTML Body:
<body>
<div id="ticket"></div>
</body>
And my CSS:
body{
margin: 0;
padding: 0;
height: 82mm;
width: 203mm;
background: red;
}
#ticket{
height: 82mm;
width: 203mm;
background-color: red;
margin: 0 auto;
}
@page{
size: 203mm 82mm;
margin: 0;
padding: 0;
}
I’ve chosen red to see it better. Even when the Body has the same color as the ticket, I still get an odd border in the printpreview (see Image blow)
The white bar is also seen on the actual pdf.
Can anyone help me?
2
Answers
After deleting the
and a pc restart i inserted agian the snippet. It works now.
The default margins on the page are removed by setting the margin attribute of the @page rule to 0. Similar to this, removing the default margins from the body element requires setting the margin property of the body rule to 0. By doing this, you should guarantee that your ticket fills the whole page and that the white bar is gone.
Additionally, you can think about setting the #ticket element’s box-sizing attribute to border-box, which includes the padding and border in the element’s total width and height so you won’t have to worry about them influencing the ticket’s overall dimensions. Here is your CSS changed with the following changes: