Skip to main content
Skip table of contents

pdfHTML: Line Height property support

In pdfHTML 3.0.0 (released with iText 7.1.11) support was added for the line-height property for inline-level elements as well as improved support for block-level elements.

Details

  • The line-height property defines the amount of space above and below inline elements.
  • Browsers use logic to calculate the maximum line height independent of the font, and the minimum value required to place the glyph is taken as the resultant line height value.
  • For some fonts, iText uses the values of WinAscender/WinDescender, but for others iText uses TypoAscender/TypoDescender and multiplies them by 1.2. This is done deliberately to avoid cases when leading is set to a multiplied value of "1" and font glyph instructions actually draw the glyph outside of the defined bounds. This is not super common, but still happens for some fonts, and this results in overlapping of glyphs from different lines.
  • In pdfHTML 3.x, you will notice that the contents are properly aligned within the elements.

Below is an example demonstrating the new behavior:

XML
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <style>
        @font-face {
            font-family: "Noto Sans";
            src: url("NotoSans-Regular.ttf");
        }
    </style>
</head>

<body>
<div style="font-size:20px; width: 600px; height: 500px; border:1px solid; font-family: 'Noto Sans'; line-height: normal">
    This is a test example. This is a test example. This is a test example.This is a test example.This is a test example.
    This is a test example. This is a test example. This is a test example.This is a test example.This is a test example.
    This is a test example. This is a test example. This is a test example.This is a test example.This is a test example.
    This is a test example. This is a test example. 

    This is a test example para 2. This is a test example para 2. This is a test example para 2.This is a test example 2.
    This is a test example para 2. This is a test example para 2. This is a test example para 2.This is a test example 2.
    This is a test example para 2. This is a test example para 2. This is a test example para 2.This is a test example 2.

    This is a test example para 3. This is a test example para 3. This is a test example para 3.This is a test example 3.
    This is a test example para 3. This is a test example para 3. This is a test example para 3.This is a test example 3.
    This is a test example para 3.This is a test example para 3. This is a test example para 3.This is a test example 3.
    
</div>
</body>
</html>


Resources

NotoSans-Regular.ttf output.pdf



JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.