I'm using html2pdf and I want to get rid of the top and left margins using css but I can't. Before output buffering margin is already set to 0, it works on html but when I convert it to pdf using html2pdf the top and left margins appears again.
Here's my current css.
body {
margin: 0;
padding: 0;
}
#box {
margin: 0;
padding: 0;
width: 803px;
height: 1400px;
border: 1px solid #000;
}
Please help.
Adjusting the Margin Size of an HTML Element With CSS This margin is automatically created by some browsers to allow for space between the edges of the viewport and the website content. You can remove this margin by setting the top and left margin to zero.
If the total space on the left you need is 50% - 300px, then you could do something like this: padding-left: 50%; // Padding can't be negative margin-left: -300px; If you're doing a border or something that will make padding not work, then simply add another div around your current one, with the above styling.
You can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.
The margin-left CSS property sets the margin area on the left side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
I suspect that the margins are generated by html2pdf, not from the html/css. Have you tried to set the margins in the html2pdf-constructor?
E.g. with array(0, 0, 0, 0)
as last parameter:
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(0, 0, 0, 0));
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