I'm trying to create a PDF using dompdf version 0.6.1 (latest at the time of writing) and am stuck at very initial step, the page size. I'm trying to create A4
size PDF. Following is my markup
$html = <<<HTML
<html>
<head>
<style>
@page {size: 21cm 29.7cm; margin: 0;}
</style>
</head>
<body>
testing
</body>
</html>
HTML;
$dompdf = new DOMPDF();
$dompdf->set_paper('a4', 'portrait');
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("title.pdf");
The PDF is created but it is always 32.07cm
wide. I've tried to play around with dompdf DPI settings by overriding the DOMPDF_DPI
constant but it only affects the content scaling, not the page size. Setting size
CSS property value to a4
doesn't help either.
I've exhausted my searching options but havn't found a solution. Any help will be greatly appreciated. Thanks.
Update
The duplicate question doesn't have an accepted answer and the better looking among the two answers has following as a solution
$dompdf->set_paper(array(0, 0, 595, 841), 'portrait');
the array parameter provided to DOMPDF::set_paper()
is just an alternative representation of A4
size in points. I've tried it and it doesn't work. The actual issue here is that no matter how one sets the paper size, the PDF size is always 152% of it.
Update 2
I'm having same issue as "Kornel N" writes in this forum post https://groups.google.com/forum/#!topic/dompdf/I_j6R4_9ZwA
I switched to dompdf recently, I was using ufpdf before. I got used to the size of an
A4
document when creating some invoices with tables.Now, when I set the paper size to
A4
($dompdf->set_paper('a4', 'portrait');
) I get a much bigger area.I extended the
write_log
method with the paper size, it says it'sA4
, as I set it.The
cpdf_adapter.cls.php
file states the size of theA4
is595.28,841.89 points
, as I got used to it.When I open the generated pdf with pdf reader software, it says it's size is
8.27 x 11.69in
, that is the size of anA4
sheet.Still, when I try to draw a rectangle to fill the sheet (just a div with a 1px border) I have to make it
791px x 1101px
big to match the paper size.The bottom border is then about
20px
from the bottom of the page, but if I try to increase the height of the div dompdf just adds one more blank page to the document, like there was an invisible bottom margin for the div, or padding for the page. There is no such, because I set it in the css.@page { margin: 0in 0in 0in 0in;} .oldal{width:791px; height:1101px; border:1px solid red;}
Please, help me, why is that happening? Is this size OK or should it be as defined?