Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom width and height of pdf using dompdf?

Tags:

php

dompdf

When I create my pdf using dompdf it generates it as default width and height. I want to set custom width and height of my created pdf. If it is not possible in dompdf then kindly suggest some other plugin for php.

like image 974
Saurabh Gupta Avatar asked Aug 19 '14 06:08

Saurabh Gupta


People also ask

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.

How do you insert 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; . To ask dompdf to avoid breaking inside an element you would use page-break-inside: avoid; .


1 Answers

By default it's going to render on 'US Letter', you can change this by using:

$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait');

You can use 'letter', 'legal', 'A4', etc..

Nevertheless you can set your own size like this:

$customPaper = array(0,0,360,360);
$dompdf->set_paper($customPaper);

More info: https://github.com/dompdf/dompdf/wiki/Usage

like image 142
Jorge Caballero Avatar answered Sep 28 '22 02:09

Jorge Caballero