* @copyright 2002-2026 Nicola Asuni - Tecnick.com LTD * @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-pdf * * This file is part of tc-lib-pdf software library. */ // NOTE: run make deps 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')); $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: 'mm', isunicode: true, subsetfont: false, compress: true, mode: '', objEncrypt: null, ); $pdf->setCreator('tc-lib-pdf'); $pdf->setAuthor('Nicola Asuni'); $pdf->setSubject('tc-lib-pdf example: 028'); $pdf->setTitle('Text hyphenation with soft hyphens'); $pdf->setKeywords('TCPDF tc-lib-pdf example text hyphenation soft hyphen shy html'); $pdf->setPDFFilename('028_text_hyphenation.pdf'); $pdf->setViewerPreferences(['DisplayDocTitle' => true]); $pdf->enableDefaultPageContent(); $setFont = static function (\Com\Tecnick\Pdf\Tcpdf $pdf, string $family, string $style, int $size): void { $font = $pdf->font->insert($pdf->pon, $family, $style, $size, 0.0, 1.0); $pdf->page->addContent($font['out']); }; // Insert one neutral font before addPage() so page context has a valid current font. $pdf->font->insert($pdf->pon, 'helvetica', '', 10, 0.0, 1.0); $pdf->addPage(); $setFont($pdf, 'helvetica', 'B', 20); $pdf->page->addContent($pdf->getTextCell( 'Example of Text Hyphenation', 15.0, 22.0, 180.0, 0.0, drawcell: false, valign: 'T', halign: 'L', )); $setFont($pdf, 'helvetica', '', 10); $pdf->page->addContent($pdf->getTextCell( 'The text below uses explicit soft hyphens () inside words and is rendered in a narrow left-aligned column.', 15.0, 34.0, 180.0, 0.0, drawcell: false, valign: 'T', halign: 'L', )); $setFont($pdf, 'times', '', 10); $html = '