Boriss
Boriss

Reputation: 554

DOMPDF what is wrong with text height?

I Have been struggling with an issue in DOMPDF for a week now...

So I have an HTML template file that needs to be converted into PDF. I load and measure the height of the template file using jQuery, and then call DOMPDF to convert the template file and I also pass the height to DOMPDF so that all content will fit on the first PDF page. (I don't want standard A4 pages pages, I want to have only one page with variable height).

It works perfectly.

But one thing screws everything up. Even tough I set font-size and line-height in the CSS, the text is rendered in DOMPDF higher than in HTML. And because of that height everything shifts down and pushes the last element on the page to a new page.

What is wrong with text height and DOMPDF? How to have consistent text height?

The only thing that has worked so far is setting a fixed height for the DIV, and setting the line-height 1px smaller than the DIV's height (probably because it leaves a small 'padding-like' space).

Upvotes: 4

Views: 5908

Answers (2)

Thanks a lot ! I am under dompdf 0.8.6

the value is in the file dompdf.php in the config folder of my laravel project.

Initial value is set to 1.1 :

"DOMPDF_FONT_HEIGHT_RATIO" => 1.1,

Personnaly i set 0.75 but i have to adujst line-height of elements such as h1

Don't forget to clear config to make the new value effective :

php artisan config:clear

Upvotes: 1

user562529
user562529

Reputation: 951

I don't want to steal the answer which was given in the comments, but it in fact works as described: Fiddle with DOMPDF_FONT_HEIGHT_RATIO. My magic number was 0.75 (at 300dpi if that matters).

define("DOMPDF_FONT_HEIGHT_RATIO", 0.75);

Thanks and credits to BrianS and Boriss!

Upvotes: 7

Related Questions