Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print margins in DOMPDF

Tags:

php

pdf

dompdf

I'm trying to generate a PDF using DOMPDF. I have some HTML which is then converted into a PDF.

But I have a problem. When I put an object at the top of the page (e.g. an icon), in the PDF it's also show on the top of the page. But when I print the PDF there is a margin. I know that there has to be a minimal margin, but in my case it's just too large. Is there some way to control this margin in DOMPDF?

I'm trying to reproduce an existing document and in the original the logo is not on the top of the page (there is already a margin in the PDF). But when I print it, it's located at the exact same position as in the PDF generated by me (and there is no margin in the PDF).

Is there somewhere a print margin already set in the PDF?

like image 671
cyrodiil Avatar asked Jul 25 '12 11:07

cyrodiil


People also ask

How do I change the paper size in Dompdf?

How do I change page size in Dompdf? $dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait'); You can use 'letter', 'legal', 'A4', etc.. With dompdf 0.6 you can also use the CSS @page rule to set your page size/orientation. e.g. @page { size: a4 landscape; } or @page { size: 360pt 360pt; } .

How do you do a page break in Dompdf?

How do you do a page-break in Dompdf? Using page-break-inside: auto; basically says to dompdf "do what you would normally do when breaking pages." To force a page break before/after your table you would use page-break-before: always; / page-break-after: always; .

How do I add a footer in Dompdf?

Just like the header, we will put our footer in a footer tag inside the body tag of the template. Just like header, we will create a space for our footer on every page then use part of the space for our footer. For the body content, put everything in a main tag inside the body tag of the template.


1 Answers

The following style will effectively set the margins of your document to 0:

@page { margin: 0px; } body { margin: 0px; } 

@page is used by dompdf 0.6.0, body by dompdf 0.5.1. You can modify the margin of the page and body independently, though right now the margin of the two together acts as your content bounds.

like image 52
BrianS Avatar answered Sep 28 '22 04:09

BrianS