Search code examples
phpdompdf

How to set custom width and height of pdf using 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.


Solution

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

    $dompdf->setPaper(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->setPaper($customPaper);
    

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