* @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')); // main TCPDF object with font subsetting enabled $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: \Com\Tecnick\Pdf\Page\Unit::Millimeter, isunicode: true, subsetfont: true, 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: 068'); $pdf->setTitle('Font Subsetting Example'); $pdf->setKeywords('TCPDF tc-lib-pdf example font subsetting'); $pdf->setPDFFilename('068_font_subset.pdf'); // 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 content demonstrating varied character sets for subsetting $html = <<<'EOD'

Font Subsetting Example

This document demonstrates font subsetting with DejaVu Sans font.

Font subsetting reduces the file size by including only the characters that are actually used in the document, rather than embedding the entire font.

Character Sets

English: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG - the quick brown fox jumps over the lazy dog.

Numbers: 0123456789 · π ≈ 3.14159

Punctuation: !@#$%^&*()[]{}–—«»‹›„“”‚‘’"'

Symbols: © ® ™ € £ ¥ ¢ § ¶ • ‰

Benefits of Font Subsetting

Text Samples

Regular text in DejaVu Sans font for testing character coverage.

Bold text is also included in the subset.

EOD; // render the HTML content $pdf->addHTMLCell(html: $html, posx: 15, posy: 15, width: 180); // Get the PDF content $rawpdf = $pdf->getOutPDFString(); // Render the PDF content $pdf->renderPDF(rawpdf: $rawpdf);