I am using dompdf (a PHP library) to create a PDF page and I have a problem to set proper dimensions. When I use CSS property:
@page {
size: 21cm 29.7cm;
}
… and for example I want to have the upper part of the page in red color, the PDF file is OK, but after print I got white margin. How can I fix it?
You've set the size of the page, but not the content boundaries. If you don't want any border on the page you have to set the page margins to 0.
@page {
size: 21cm 29.7cm;
margin: 0;
}
This removes the margin around the body, but it also means that your content will bump up against the page edge. If you want the body content to having some spacing from the edge give it some padding.
body {
padding: .5in;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With