Re: Paper size in pixels doesn't match actual size

3,759 views
Skip to first unread message

Fabien Ménager

unread,
Nov 14, 2012, 4:29:52 AM11/14/12
to dom...@googlegroups.com
Hello, sorry for the late reply.
Which version of dompdf are you using ? We recommend using the 0.6 beta 3 or the trunk.
Could you try the patch shown here : http://code.google.com/p/dompdf/issues/detail?id=550
And tell us if it fixes your problem ?


Le mercredi 14 novembre 2012 08:42:17 UTC+1, jesse smith a écrit :
Wow, seems you posted two weeks ago and no response yet. I just started using dompdf today and I am having the same issue with a letter size page 8.5x11.

Did you ever find a fix for this?

On Tuesday, October 30, 2012 1:23:55 AM UTC-7, Kornel N wrote:
Hi!

I switched to dompdf recently, I was using ufpdf before. I got used to the size of an A4 document when creating some invocies 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's A4, as I set it.
The cpdf_adapter.cls.php file states the size of the A4 is 595.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.27x11.69 in, that is the size of an A4 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 791x1101 px 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?

Thanks,
Kornel

jesse smith

unread,
Nov 14, 2012, 4:54:15 AM11/14/12
to dom...@googlegroups.com
I downloaded the version named dompdf_0-6-0_beta3, I do not know how to implement a patch.

jesse smith

unread,
Nov 14, 2012, 5:42:21 AM11/14/12
to dom...@googlegroups.com
I assumed the minus sign at the beginning of a line in the patch meant remove those lines, so i commented them out and added a few pixels of length to my background container. Which cause the creation of the second page and pushing all of my content to the second page. Do you have any other suggestions?

BrianS

unread,
Jan 10, 2013, 5:04:08 PM1/10/13
to dom...@googlegroups.com
I believe this has to do with the translation from px to pt based on the configured DPI. DOMPDF defaults to a DPI of 96, while a PDF is standardized to a DPI of 72. When laying elements out for the PDF dompdf uses pt, and so translates lengths from px to pt based on the DPI ratio. You can avoid the translation by either specifying a DPI of 72 or using pt instead of px.

Quick testing and I don't think we've quite perfected the length translation when rending to PDF, but you'll get much closer by keeping in mind how dompdf determines the size of elements in the PDF. Plus, keep in mind that per the HTML spec the height/width is specified on the content box, so your border has to be subtracted from the desired width of the element.
Reply all
Reply to author
Forward
0 new messages