Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of the left and top margins in css when using html2pdf

Tags:

css

php

html2pdf

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.

like image 711
user225269 Avatar asked Jan 07 '12 11:01

user225269


People also ask

How do you get rid of the left margin in CSS?

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.

How do I set dynamic margin-left in CSS?

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.

How do you manage margins in CSS?

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.

What is margin-left CSS?

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.


1 Answers

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));
like image 164
scessor Avatar answered Oct 05 '22 07:10

scessor