* @copyright 2002-2026 Nicola Asuni - Tecnick.com LTD * @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE) * @link https://github.com/tecnickcom/tc-lib-pdf * * This file is part of tc-lib-pdf software library. */ // NOTE: local file reads (images, fonts, attachments) are restricted to an allowlist of // trusted paths that covers this package tree, so run the examples in place. To read assets // from other locations, list them in the 'allowedPaths' entry of the fileOptions constructor // parameter (see E047_remote_resources_security.php). // NOTE: run make fonts in the project root to generate the dependencies and example fonts. // autoloader when using Composer require __DIR__ . '/../vendor/autoload.php'; // define fonts directory \define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts')); // autoloader when using RPM or DEB package installation //require ('/usr/share/php/Com/Tecnick/Pdf/autoload.php'); // main TCPDF object $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: \Com\Tecnick\Pdf\Page\Unit::Millimeter, isunicode: true, subsetfont: false, compress: true, mode: \Com\Tecnick\Pdf\PdfConformance::None, objEncrypt: null, ); // ---------- $pdf->setCreator('tc-lib-pdf'); $pdf->setAuthor('Nicola Asuni'); $pdf->setSubject('tc-lib-pdf example: 069'); $pdf->setTitle('HTML Line Height'); $pdf->setKeywords('TCPDF tc-lib-pdf html css line-height typography spacing'); $pdf->setPDFFilename('069_html_line_height.pdf'); $pdf->setViewerPreferences(['DisplayDocTitle' => true]); $pdf->enableDefaultPageContent(); // Insert DejaVu Sans font for subsetting test $bfont = $pdf->font->insert($pdf->pon, 'dejavusans', '', 12); // Add first page $page = $pdf->addPage(); // Add font to the page $pdf->page->addContent($bfont['out']); $html = <<Line-Height CSS Tests

1) Line-height with percentages

Line-height: 100%
This paragraph uses a line-height of 100%, which is the same as the font size. Each line should be tightly spaced without extra vertical space. This is useful when you want compact text layout.

Line-height: 150%
This paragraph uses a line-height of 150%, which adds moderate spacing between lines. The lines are more readable and have better visual separation. This is a common default setting for body text in many documents.

Line-height: 200%
This paragraph uses a line-height of 200%, which doubles the font size for vertical spacing. The lines have significant space between them, making the text very readable. This is often used for accessibility or when line spacing is deliberately increased.

2) Line-height with absolute units

Line-height: 10pt
This paragraph uses an absolute line-height of 10 points. The spacing between lines is fixed at exactly 10 points. The font size remains 10pt, so this creates tightly packed lines.

Line-height: 15pt
This paragraph uses an absolute line-height of 15 points. Each line has exactly 15 points of vertical space allocated. This provides moderate spacing for improved readability.

Line-height: 20pt
This paragraph uses an absolute line-height of 20 points. The lines are well-spaced with 20 points of vertical space each. This creates a more spacious and airy appearance in the document.

3) Line-height with relative units (em)

Line-height: 0.8em
This paragraph uses a line-height of 0.8em, which is 80% of the current font size. The lines are compressed together with minimal vertical space. This is useful for creating a compact visual effect.

Line-height: 1.2em
This paragraph uses a line-height of 1.2em, which is 120% of the current font size. The lines have a balanced amount of spacing for good readability. This is similar to using a 120% line-height percentage.

Line-height: 2em
This paragraph uses a line-height of 2em, which is 200% of the current font size. The lines are widely separated with generous vertical spacing. This creates a very open and spacious text layout.

4) Line-height with unitless numbers

Line-height: 0.9 (unitless)
This paragraph uses a unitless line-height value of 0.9. The multiplier is applied to the font size (0.9 × 10pt = 9pt). This creates compact line spacing.

Line-height: 1.5 (unitless)
This paragraph uses a unitless line-height value of 1.5. The multiplier is applied to the font size (1.5 × 10pt = 15pt). This is a very popular setting for comfortable reading. The spacing is proportional to the font size.

Line-height: 2.5 (unitless)
This paragraph uses a unitless line-height value of 2.5. The multiplier is applied to the font size (2.5 × 10pt = 25pt). The lines are very widely spaced and easy to read. This is often used for accessibility requirements.

5) Line-height with millimeters

Line-height: 5mm
This paragraph uses an absolute line-height of 5 millimeters. The vertical spacing between lines is exactly 5mm. Different units like millimeters are sometimes used in print design.

Line-height: 8mm
This paragraph uses an absolute line-height of 8 millimeters. The increased spacing makes the text more readable and open. Millimeters are useful for precise layout control in documents.

6) Comparison: normal vs specific values

Line-height: normal
This paragraph uses the default line-height value (typically around 1.0-1.2). The spacing is determined by the browser or PDF renderer default. This is the baseline for comparison with other values.

Line-height: 1 (unitless)
This paragraph uses a unitless line-height of exactly 1. The vertical space is the same as the font size. This creates tightly spaced lines with minimal separation.

(1) default
line
height

(2) normal
line
height

(3) 100%
line
height

(4) 50%
line
height

(5) 150%
line
height

(6) 10mm
line
height

(7) 20mm
line
height

check
line
after
BR
check
line
after
DIV
EOF; $pdf->addHTMLCell(html: $html, posx: 20, posy: 10, width: 150); // ---------- // get PDF document as raw string $rawpdf = $pdf->getOutPDFString(); // Various output modes: //$pdf->savePDF(\dirname(__DIR__).'/target', $rawpdf); $pdf->renderPDF(rawpdf: $rawpdf); //$pdf->downloadPDF($rawpdf); //echo $pdf->getMIMEAttachmentPDF($rawpdf);