* @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('OUTPUT_FILE', \realpath(__DIR__ . '/../target') . '/example.pdf'); // 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: 018'); $pdf->setTitle('HTML Page Span Handling'); $pdf->setKeywords('TCPDF tc-lib-pdf html page span pagination flow layout'); $pdf->setPDFFilename('018_html_page_span.pdf'); $pdf->setViewerPreferences(['DisplayDocTitle' => true]); $pdf->enableDefaultPageContent(); // ---------- // Insert fonts $bfont1 = $pdf->font->insert($pdf->pon, 'helvetica', '', 12); // test images directory $imgdir = \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-image/test/images/'); $pageV01 = $pdf->addPage(); $bfont6 = $pdf->font->insert($pdf->pon, 'dejavusans', '', 10); $pdf->page->addContent($bfont6['out']); $html = 'Some special characters: < € € € & è è © > \\slash \\\\double-slash \\\\\\triple-slash

List

List example:
  1. bold text
  2. italic text
  3. underlined text
  4. bbibiubib
  5. link to https://tcpdf.org
  6. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
    Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
  7. SUBLIST
    1. row one
      • sublist
    2. row two
  8. TEST line through
  9. font + 3
  10. small text normal small text normal subscript normal superscript normal
Coffee
Black hot drink
Milk
White cold drink
The words “מזל [mazel] טוב [tov]” mean “Congratulations!”

This is just an example of html code to demonstrate some supported CSS inline styles. bold text line-trough underline and line-trough color background color bold xx-small x-small small medium large x-large xx-large

'; $pdf->addHTMLCell( html: '

HTML page break example

' . $html . $html . $html . $html, posx: 20, posy: 10, width: 150, ); // ============================================================= // Styled block (background + border) spanning multiple pages. $blockchunk = '

' . 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium ' . 'doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore ' . 'veritatis et quasi architecto beatae vitae dicta sunt explicabo.' . '

'; $blockhtml = '

Styled block across pages

' . '
' . '

Block-level container — the background and border continue ' . 'on each page until the content ends.

' . \str_repeat($blockchunk, 30) . '
'; $pdf->addHTMLCell(html: $blockhtml, posx: 20, posy: 100, width: 150); // ============================================================= // Table spanning multiple pages with header row replay. $tableRows = ''; for ($i = 1; $i <= 20; ++$i) { $tableRows .= '' . '' . $i . '' . 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' . '' . \number_format($i * 12.34, 2) . '' . ''; } $tablehtml = '

Table across pages

' . '' . '' . '' . '' . '' . '' . $tableRows . '
#DescriptionAmount
'; $pdf->addHTMLCell(html: $tablehtml, posx: 20, posy: 220, width: 150); // ============================================================= // Table rows containing DIV blocks with an explicit CSS height. // Odd rows use a styled DIV (text color + background color), even rows // use a bare DIV with only the height set: both must produce the same // row height, and no row may be split across pages. $tableRowsB = ''; for ($i = 1; $i <= 8; ++$i) { $divstyleB = ($i % 2) === 1 ? 'color:blue; background-color:yellow; height:100px;' : 'color:#007700; height:100px;'; $tableRowsB .= '' . '' . $i . '' . '
DIV block #' . $i . ' (100px high)
' . '' . \number_format($i * 12.34, 2) . '' . ''; } $tablehtmlB = '

Fixed-height DIV blocks inside table cells

' . '' . '' . '' . '' . '' . '' . $tableRowsB . '
#DescriptionAmount
'; $pdf->addHTMLCell(html: $tablehtmlB, posx: 20, posy: 170, 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);