### Run local example environment Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/README.md Commands to prepare the environment by generating fonts and starting a local PHP server for testing examples. ```bash make fonts # generate the companion fonts used by the examples make server # start a local PHP server ``` -------------------------------- ### Initialize local development environment Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/CONTRIBUTING.md Commands to clone the repository and install dependencies. ```bash git clone https://github.com/tecnickcom/tc-lib-pdf.git cd tc-lib-pdf make deps make qa ``` -------------------------------- ### Check library version Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/CONTRIBUTING.md Command to retrieve the installed version of the library via Composer. ```bash composer show tecnickcom/tc-lib-pdf ``` -------------------------------- ### Selective Cache Implementation Example Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md An example implementation that only caches font subsets. ```php use Com\Tecnick\Pdf\Cache\CacheInterface; use Com\Tecnick\Pdf\Cache\SelectiveCacheInterface; $cache = new class implements SelectiveCacheInterface { /** @var array */ private array $store = []; public function supports(string $type): bool { return $type === CacheInterface::TYPE_FONT; } public function get(string $key): mixed { return $this->store[$key] ?? null; } public function set(string $key, mixed $value): void { $this->store[$key] = $value; } }; ``` -------------------------------- ### Install tc-lib-pdf via Composer CLI Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/README.md Use the Composer command line tool to add the package to your project. ```bash composer require tecnickcom/tc-lib-pdf ``` -------------------------------- ### Configure Remote Resources and cURL Options Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/REMOTE_RESOURCES.md Example of initializing Tcpdf with restricted remote hosts, specific allowed local paths, and enforced cURL security settings. ```php $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: 'mm', fileOptions: [ 'allowedHosts' => ['cdn.example.com'], 'allowedPaths' => [ (string) realpath(sys_get_temp_dir()), (string) realpath(__DIR__ . '/../storage/pdf-assets'), (string) realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'), ], 'markupAllowedPaths' => [ (string) realpath(__DIR__ . '/../storage/pdf-assets'), (string) realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'), ], 'maxRemoteSize' => 10 * 1024 * 1024, // 10 MiB 'curlopts' => [ CURLOPT_TIMEOUT => 10, CURLOPT_CONNECTTIMEOUT => 5, ], 'fixedCurlOpts' => [ CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, ], ], ); ``` -------------------------------- ### Minimal In-Memory Cache Implementation Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md A basic example of an in-memory cache using an anonymous class. ```php use Com\Tecnick\Pdf\Cache\CacheInterface; $cache = new class implements CacheInterface { /** @var array */ private array $store = []; public function get(string $key): mixed { return $this->store[$key] ?? null; } public function set(string $key, mixed $value): void { $this->store[$key] = $value; } }; ``` -------------------------------- ### Incorrect font selection example Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md This example demonstrates an incorrect approach where the text is measured and encoded using the font currently on the stack rather than the intended font. ```php // Wrong: the text is measured and encoded with the font that is current on the stack, // which is $fontB here, whatever operator was added to the page. $fontA = $pdf->font->insert($pdf->pon, 'dejavusans', 'B', 18); $fontB = $pdf->font->insert($pdf->pon, 'dejavusans', '', 10); $pdf->page->addContent($fontA['out']); $pdf->page->addContent($pdf->getTextCell(txt: 'Heading', posx: 15, posy: 20, width: 180)); ``` -------------------------------- ### Format commit messages Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/CONTRIBUTING.md Examples of imperative-mood commit messages using standard prefix tags. ```text fix: correct path traversal in font loader feat: add support for CSS grid layout test: add regression test for #123 docs: update CONTRIBUTING workflow refactor: extract text measurement into helper ``` -------------------------------- ### Configure composer.json for font generation Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Add these scripts to your project's composer.json to ensure fonts are generated automatically during installation and updates. ```json { "scripts": { "tc-lib-pdf-fonts": [ "[ -d vendor/tecnickcom/tc-lib-pdf-font ] && make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts || true" ], "post-install-cmd": [ "@tc-lib-pdf-fonts" ], "post-update-cmd": [ "@tc-lib-pdf-fonts" ] } } ``` -------------------------------- ### Register PDF Source and Get Page Count Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/PDF_IMPORT.md Registers a source PDF file or raw bytes and retrieves the total number of reachable pages. ```php $sourceId = $pdf->setImportSourceFile('/path/to/source.pdf'); // or: $sourceId = $pdf->setImportSourceData($rawPdfBytes); $count = $pdf->getSourcePageCount($sourceId); ``` -------------------------------- ### Bootstrap Library with System Autoloader Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DEVELOPMENT.md Include this file when using the library via system-level RPM or DEB packages. ```php require_once '/usr/share/php/Com/Tecnick/Pdf/autoload.php'; ``` -------------------------------- ### Import custom fonts Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Commands to prepare directories, download a font, and convert it to PHP font data. ```bash mkdir -p target/fonts/source target/fonts/custom curl -fL --retry 3 -o target/fonts/source/NotoSans-Regular.ttf \ https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSans/NotoSans-Regular.ttf php vendor/tecnickcom/tc-lib-pdf-font/util/convert.php \ --outpath=target/fonts/custom \ --type=TrueTypeUnicode \ --flags=32 \ --encoding_id=10 \ --fonts=target/fonts/source/NotoSans-Regular.ttf ``` -------------------------------- ### Run preflight matrix Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/resources/preflight/README.md Executes the preflight process from the repository root. ```bash make preflight ``` -------------------------------- ### Run project tests Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/CONTRIBUTING.md Commands to execute the full test suite or specific test files using PHPUnit and make. ```bash # Run the full test suite make test # Run a specific test file XDEBUG_MODE=coverage ./vendor/bin/phpunit test/AFRelationshipTest.php ``` -------------------------------- ### Initialize PDF/X modes Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Configure the Tcpdf constructor with specific PDF/X profile modes to enforce print-exchange standards. ```php // Generic PDF/X alias (same constraints as pdfx3) $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfx'); // Specific variants $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfx1a'); // PDF/X-1a:2003 $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfx3'); // PDF/X-3:2003 $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfx4'); // PDF/X-4:2010 $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfx5'); // PDF/X-5g:2010 ``` -------------------------------- ### Generate a basic PDF document Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/README.md A minimal script to initialize the PDF object, add a page, insert content, and render the output. ```php font->insert($pdf->pon, 'helvetica', '', 12); $page = $pdf->addPage(); $pdf->page->addContent($bfont['out']); $html = '

Hello, PDF!

Generated with tc-lib-pdf.

'; $pdf->addHTMLCell( html: $html, posx: 15, // mm from left page edge posy: 20, // mm from top page edge width: 180, // mm wide (0 = to right margin) ); $rawpdf = $pdf->getOutPDFString(); $pdf->renderPDF($rawpdf); ``` -------------------------------- ### Run quality assurance suite Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/CONTRIBUTING.md Executes formatting checks, linting, static analysis, and the full unit-test suite. ```bash make qa ``` -------------------------------- ### Packaging Makefile Commands Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DEVELOPMENT.md Commands to generate system-level distribution packages for RPM and DEB formats. ```bash make rpm # build RPM package -> target/RPM/ make deb # build DEB package -> target/DEB/ ``` -------------------------------- ### Run preflight with custom output directory Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/resources/preflight/README.md Executes the preflight matrix script while specifying a custom directory for output reports. ```bash bash resources/preflight/run_preflight_matrix.sh /tmp/tc-lib-pdf-preflight ``` -------------------------------- ### Generate and format self-signed certificates with OpenSSL Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DIGITAL_SIGNATURES.md Use these commands to create a new RSA key and certificate, combine them, or export them to PKCS#12 format. ```bash openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -sha256 \ -keyout tcpdf.key -out tcpdf.crt \ -subj "/CN=tc-lib-pdf test certificate" # combine into a single file (as the bundled demo does), or reference them separately cat tcpdf.crt tcpdf.key > tcpdf.pem # convert to PKCS#12 if needed openssl pkcs12 -export -in tcpdf.crt -inkey tcpdf.key -out tcpdf.p12 ``` -------------------------------- ### Development Makefile Commands Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DEVELOPMENT.md Use these commands to manage dependencies, view available targets, run quality assurance checks, and perform preflight validations. ```bash # Install all development dependencies make deps # List all available Make targets make help # Run the full quality pipeline (lint, static analysis, tests, coverage) make qa # Generate PDF/X + PDF/UA sample matrix and run external validators (if installed) make preflight ``` -------------------------------- ### Generate fonts via one-liner Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md An alternative command to trigger font generation from the project root. ```bash make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts ``` -------------------------------- ### Run preflight with PDF/X validator hook Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/resources/preflight/README.md Executes the preflight process while providing a custom command for PDF/X validation. ```bash PDFX_VALIDATOR_CMD='my-pdfx-validator --mode "$MODE" "$FILE"' make preflight ``` -------------------------------- ### Initialize PDF/UA mode Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Configure the Tcpdf constructor with the appropriate mode string to enable PDF/UA accessibility features. ```php // Generic PDF/UA alias $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfua'); // Specific parts $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfua1'); // PDF/UA-1 (PDF 1.7) $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfua2'); // PDF/UA-2 (PDF 2.0) ``` -------------------------------- ### Import and Place a Single Page Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/PDF_IMPORT.md Imports a specific page as a template and places it onto the current document page with specified dimensions and alignment. ```php $tpl = $pdf->importPage($sourceId, 1, [ 'box' => 'CropBox', // MediaBox|CropBox|BleedBox|TrimBox|ArtBox 'groupXObject' => true, 'cache' => true, 'respectRotation' => true, ]); $pdf->addPage(); $placed = $pdf->useImportedPage($tpl, 20, 20, 120, 80, [ 'keepAspectRatio' => true, 'align' => 'CC', // TL|TC|TR|CL|CC|CR|BL|BC|BR 'clip' => true, ]); ``` -------------------------------- ### Pinning metadata for reproducible output Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Set creation date, modification date, and file identifier to ensure consistent document output. ```php $pdf->setDocCreationDate(1600000000); $pdf->setDocModificationDate(1600000000); $pdf->setFileId('any string, or 32 hexadecimal digits'); ``` -------------------------------- ### Trigger font generation via Composer Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Run these commands to trigger the font generation process. ```bash composer install composer update composer require ... ``` -------------------------------- ### Configure LTV settings Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DIGITAL_SIGNATURES.md Enables LTV by configuring the signature profile and embedding OCSP responses, CRL payloads, and certificate data. ```php $pdf->signature()->configure([ 'profile' => 'pades-b-lt', 'signcert' => 'file:///path/to/cert.pem', 'privkey' => 'file:///path/to/key.pem', 'password' => '', 'ltv' => [ 'enabled' => true, 'embed_ocsp' => true, // fetch OCSP responses 'embed_crl' => true, // fetch CRL payloads (fallback) 'embed_certs' => true, // include certificate DER bytes 'include_dss' => true, // emit /DSS in the catalog 'include_vri' => true, // emit /VRI map keyed by signature SHA-1 ], ]); ``` -------------------------------- ### Configure PDF/A Conformance Modes Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Pass the desired PDF/A mode string to the Tcpdf constructor to enable archival-compliant output. ```php // PDF/A-1b (default conformance level when suffix is omitted) $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa1'); // Explicit conformance levels $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa1a'); // PDF/A-1a $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa1b'); // PDF/A-1b $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa2a'); // PDF/A-2a $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa2b'); // PDF/A-2b $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa2u'); // PDF/A-2u $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa3a'); // PDF/A-3a $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa3b'); // PDF/A-3b $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa3u'); // PDF/A-3u ``` -------------------------------- ### Implement CacheInterface Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md Define the required interface for custom cache backends. Implementations must not throw exceptions. ```php namespace Com\Tecnick\Pdf\Cache; interface CacheInterface { public function get(string $key): mixed; // stored value, or null on a miss public function set(string $key, mixed $value): void; } ``` -------------------------------- ### Configuring XMP padding Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Remove XMP padding to declare the metadata packet read-only and reduce file size. ```php $pdf->setXMPPaddingLines(0); ``` -------------------------------- ### Generate fonts manually Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Execute the build process manually from within the font package directory. ```bash cd vendor/tecnickcom/tc-lib-pdf-font make fonts ``` -------------------------------- ### Configure and Place Digital Signature Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DIGITAL_SIGNATURES.md Configures signature parameters, timestamp settings, and visual appearance using the fluent API. ```php $pdf->signature() ->configure([ 'profile' => 'pades-b-t', // legacy | pades-b-b | pades-b-t | pades-b-lt | pades-b-lta 'digest_algorithm' => 'sha256', // sha256 | sha384 | sha512 'signcert' => 'file:///path/to/cert.pem', 'privkey' => 'file:///path/to/key.pem', 'password' => '', 'extracerts' => 'file:///path/to/chain.pem', // optional issuer chain 'cert_type' => 2, 'info' => [ 'Name' => 'Jane Smith', 'Location' => 'London', 'Reason' => 'Document approval', 'ContactInfo' => 'jane@example.com', ], ]) ->timestamp([ 'enabled' => true, 'host' => 'https://freetsa.org/tsr', 'hash_algorithm' => 'sha256', 'timeout' => 30, 'verify_peer' => true, 'allow_sha1' => true, // this TSA still uses the SHA-1 v1 attribute ]); $pdf->signature()->appearance()->place(posx: 15, posy: 35, width: 90, height: 20, page: -1, name: 'Signature'); $widgetObjId = $pdf->signature()->widgetObjectId(); ``` -------------------------------- ### Retrieve PDF/X conformance warnings Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Access validation warnings after document rendering to identify annotations that violate ISO 15930 bleed box rules. ```php $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfx1a'); // ... build document ... $out = $pdf->getOutPDFString(); foreach ($pdf->getWarnings() as $warning) { // PDF/X: the /Link annotation on page 1 overlaps the BleedBox; ... } ``` -------------------------------- ### Create a new fix branch Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/CONTRIBUTING.md Command to create a new branch from main for bug fixes. ```bash git checkout -b fix/short-description-of-bug ``` -------------------------------- ### Upgrade to PAdES-BASELINE-LTA Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DIGITAL_SIGNATURES.md Upgrades a signature to PAdES-BASELINE-LTA by adding an archive timestamp over the document. ```php $pdf->signature()->configure([/* pades-b-lt + ltv */])->timestamp([/* TSA */])->upgradeToLta(); ``` -------------------------------- ### External Signature Workflow Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DIGITAL_SIGNATURES.md Configures a signature field for external signing, prepares the document bytes and digest, and applies the resulting CMS signature. ```php $pdf->signature()->external()->configure([/* ... */ 'privkey' => '', 'signcert' => '']); $prepared = $pdf->signature()->external()->prepare('sha256'); $signedPdf = $pdf->signature()->external()->apply( $prepared['prepared_pdf'], $prepared['byte_range'], $cms, 'binary', ); ``` -------------------------------- ### Setting the document identifier Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Explicitly define the document identifier for XMP metadata. ```php $pdf->setDocumentId('invoice-2026-0042'); ``` -------------------------------- ### Implement SelectiveCacheInterface Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md Define an interface to selectively enable or disable caching for specific subsystems. ```php namespace Com\Tecnick\Pdf\Cache; interface SelectiveCacheInterface extends CacheInterface { /** @param CacheInterface::TYPE_* $type */ public function supports(string $type): bool; } ``` -------------------------------- ### Controlling stream compression Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Toggle FlateDecode compression via the Tcpdf constructor. ```php // compressed output (default), in any mode $pdf = new \Com\Tecnick\Pdf\Tcpdf(compress: true, mode: 'pdfa3b'); // uncompressed output $pdf = new \Com\Tecnick\Pdf\Tcpdf(compress: false, mode: 'pdfa3b'); ``` -------------------------------- ### Append Pages from Source Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/PDF_IMPORT.md Appends multiple pages from a source document or adds a single page sized to the source dimensions. ```php // Append all pages. $templates = $pdf->appendDocument($sourceId); // Append only selected pages. $templates = $pdf->appendDocument($sourceId, [1, 3, 5]); // Add one imported page sized to the source page. $tpl = $pdf->addPageFromImport($sourceId, 2); ``` -------------------------------- ### Com\Tecnick\Pdf\Cache\CacheInterface Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md The base interface for implementing a custom cache backend. Implementations must be best-effort and must not throw exceptions. ```APIDOC ## interface Com\Tecnick\Pdf\Cache\CacheInterface ### Description Defines the contract for a cache backend. Implementations must handle misses by returning null and must not throw exceptions during get or set operations. ### Methods - **get(string $key): mixed** - Retrieves a value from the cache. Returns null on a miss. - **set(string $key, mixed $value): void** - Stores a value in the cache. ``` -------------------------------- ### Correct font selection using cloneFont Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Use cloneFont to make the desired font current on the stack, ensuring text is measured and encoded correctly. ```php $fontA = $pdf->font->cloneFont($pdf->pon, $fontA['idx'], null, $fontA['size']); $pdf->page->addContent($fontA['out']); $pdf->page->addContent($pdf->getTextCell(txt: 'Heading', posx: 15, posy: 20, width: 180)); ``` -------------------------------- ### Allowing Remote Hosts in Tcpdf Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/REMOTE_RESOURCES.md Configure the Tcpdf constructor with an array of allowed hostnames to enable fetching remote resources. ```php $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: 'mm', fileOptions: [ 'allowedHosts' => ['cdn.example.com', 'assets.myapp.io'], ], ); ``` -------------------------------- ### Add tc-lib-pdf to composer.json Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/README.md Alternatively, add the dependency directly to your project's composer.json file. ```json { "require": { "tecnickcom/tc-lib-pdf": "^8" } } ``` -------------------------------- ### Add post-autoload-dump hook Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Include this hook in your composer.json to support CI pipelines that use composer dump-autoload. ```json "post-autoload-dump": [ "@tc-lib-pdf-fonts" ] ``` -------------------------------- ### Define K_PATH_FONTS constant Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Set the path to your custom font directory before initializing the Tcpdf instance. ```php \define('K_PATH_FONTS', '/opt/app/fonts/tc-lib-pdf'); ``` -------------------------------- ### Tag decorative content as Artifact Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Use addArtifactContent to mark non-semantic elements like headers and footers as artifacts, ensuring they are ignored by assistive technologies. ```php $pid = $pdf->addPage()['pid']; $headerOperators = $pdf->graph->getLine(10, 10, 200, 10); $pdf->addArtifactContent($headerOperators, $pid, 'Pagination', 'Header'); $footerText = $pdf->getTextCell('Page 1', 180, 280, 20, 5); $pdf->addArtifactContent($footerText, $pid, 'Pagination', 'Footer'); ``` -------------------------------- ### Configure TSA Timestamp Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/DIGITAL_SIGNATURES.md Configures the TSA timestamp settings for a PDF signature using the signature() method. ```php $pdf->signature()->timestamp([ 'enabled' => true, 'host' => 'https://freetsa.org/tsr', 'username' => '', 'password' => '', 'cert' => '', 'hash_algorithm' => 'sha256', // sha256 | sha384 | sha512 'policy_oid' => '', // optional OID string 'nonce_enabled' => true, 'timeout' => 30, 'verify_peer' => true, 'allow_sha1' => false, // accept a SHA-1 token (see below) ]); ``` -------------------------------- ### Enable Cache in Tcpdf Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md Pass the cache implementation to the Tcpdf constructor. Font subsetting must be enabled for the font cache to be used. ```php $cache = new MyRedisCache(); // implements Com\Tecnick\Pdf\Cache\CacheInterface $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: 'mm', subsetfont: true, // required for the font subset cache to be exercised cache: $cache, ); ``` -------------------------------- ### Restricting Local Paths in Tcpdf Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/REMOTE_RESOURCES.md Define allowed local path prefixes for internal library operations and markup-originated resource loads. Supplying these arrays replaces the default internal allowlists entirely. ```php $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: 'mm', fileOptions: [ 'allowedPaths' => [ (string) realpath(sys_get_temp_dir()), (string) realpath(__DIR__ . '/../storage/pdf-assets'), (string) realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'), ], 'markupAllowedPaths' => [ (string) realpath(__DIR__ . '/../storage/pdf-assets'), (string) realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'), ], ], ); ``` -------------------------------- ### Convert font for supplementary-plane characters Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/FONTS.md Use the convert utility with --encoding_id=10 to support characters outside the Basic Multilingual Plane, such as emoji or CJK extensions. ```bash php vendor/tecnickcom/tc-lib-pdf-font/util/convert.php \ --outpath=target/fonts/custom \ --type=TrueTypeUnicode \ --flags=32 \ --encoding_id=10 \ --fonts=target/fonts/source/MyFont-Regular.ttf ``` -------------------------------- ### Set document language Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Explicitly define the document language using the setLanguageArray method. ```php $pdf->setLanguageArray(['a_meta_language' => 'de-DE']); ``` -------------------------------- ### Com\Tecnick\Pdf\Cache\SelectiveCacheInterface Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/CACHE.md An extension of CacheInterface that allows fine-grained control over which types of data are cached. ```APIDOC ## interface Com\Tecnick\Pdf\Cache\SelectiveCacheInterface ### Description Extends CacheInterface to allow the library to query if a specific cache type is supported before attempting to read or write. ### Methods - **supports(string $type): bool** - Returns true if the cache implementation should handle the specified type (e.g., CacheInterface::TYPE_FONT or CacheInterface::TYPE_IMAGE). ``` -------------------------------- ### Embed Factur-X/ZUGFeRD XML Payloads Source: https://github.com/tecnickcom/tc-lib-pdf/blob/main/doc/STANDARDS.md Use setFacturX to embed structured XML invoices into a PDF/A-3 document. The document must be initialized in PDF/A-3 mode. ```php $pdf = new \Com\Tecnick\Pdf\Tcpdf(mode: 'pdfa3'); // ... build document ... $pdf->setFacturX( xml: $invoiceXML, profile: \Com\Tecnick\Pdf\HybridProfile::FacturX, level: \Com\Tecnick\Pdf\HybridConformance::En16931, ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.