Skip to content

Konfiguration

TCPDF-Next wird mit sinnvollen Standardwerten geliefert, die sofort einsatzbereit sind. Jede Einstellung kann bei der Dokumenterstellung oder später über Fluent Setter überschrieben werden.

Dokument-Standardwerte

When you call Document::create(), the following defaults apply unless you specify otherwise:

SettingDefaultBeschreibung
Page sizePageSize::A4ISO A4 (210 × 297 mm)
OrientationOrientation::PortraitPortrait mode
UnitUnit::MillimeterAll measurements in millimetres
Left margin15 mmLeft page margin
Top margin27 mmTop page margin
Right margin15 mmRight page margin
Bottom margin25 mmBottom page margin
Auto page breaktrueAutomatic page break near bottom margin
FontHelvetica, 12 ptDefault font family and size
php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\Core\Enums\PageSize;
use Yeeefang\TcpdfNext\Core\Enums\Orientation;
use Yeeefang\TcpdfNext\Core\Enums\Unit;

$doc = Document::create(
    pageSize: PageSize::Letter,
    orientation: Orientation::Landscape,
    unit: Unit::Inch,
);

Ränder

Ränder can be set globally or per-page:

php
use Yeeefang\TcpdfNext\Core\ValueObjects\Margin;

// Global margins
$doc->setMargins(new Margin(
    left: 20,
    top: 30,
    right: 20,
    bottom: 25,
));

// Override for a specific page
$doc->addPage(
    margin: new Margin(left: 10, top: 10, right: 10, bottom: 10),
);

Schriftartenpfade und Verzeichnisse

TCPDF-Next looks for font files in a configurable set of directories. The built-in fonts (Helvetica, Courier, Times, Symbol, ZapfDingbats) are always available. For custom or Unicode fonts, register additional paths:

php
use Yeeefang\TcpdfNext\Core\Config\FontConfig;

$doc->configureFonts(function (FontConfig $config): void {
    // Add a directory containing .ttf / .otf files
    $config->addDirectory('/path/to/my/fonts');

    // Add a single font file with a family alias
    $config->addFont('/path/to/MyFont-Regular.ttf', alias: 'MyFont');
});

TIP

Font files are embedded as subsets by default, keeping PDF output compact. Full embedding can be enabled per font when needed.

Verschlüsselungseinstellungen

PDF encryption is configured through the EncryptionConfig value object:

php
use Yeeefang\TcpdfNext\Core\Config\EncryptionConfig;
use Yeeefang\TcpdfNext\Core\Enums\EncryptionLevel;
use Yeeefang\TcpdfNext\Core\Enums\Permission;

$doc->setEncryption(new EncryptionConfig(
    level: EncryptionLevel::AES256,
    userPassword: 'reader-pass',
    ownerPassword: 'admin-pass',
    permissions: [
        Permission::Print,
        Permission::Copy,
    ],
));
LevelBeschreibung
EncryptionLevel::RC4_40Legacy 40-bit RC4 (not recommended)
EncryptionLevel::RC4_128128-bit RC4
EncryptionLevel::AES128128-bit AES
EncryptionLevel::AES256256-bit AES (recommended)

Tagged-PDF-Einstellungen

Tagged (accessible) PDFs improve screen-reader support and are required by PDF/UA. Enable tagging globally:

php
$doc->enableTaggedPdf();

// Optionally set the document language for accessibility
$doc->setLanguage('en');

When tagged PDF mode is active, structural tags (<P>, <H1><H6>, <Table>, etc.) are emitted automatically by the text and table APIs.

Deterministischer Modus

By default, PDFs contain timestamps and unique identifiers that make every output unique. Deterministic mode strips these, producing byte-identical output for the same input — useful for snapshot testing and reproducible builds:

php
$doc->enableDeterministicMode();

WARNING

Deterministic mode removes creation/modification dates and the unique file identifier. Do not use it for documents that require these metadata fields.

Vollständiges Konfigurationsbeispiel

Below is a single snippet showing every major configuration option together:

php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\Core\Enums\PageSize;
use Yeeefang\TcpdfNext\Core\Enums\Orientation;
use Yeeefang\TcpdfNext\Core\Enums\Unit;
use Yeeefang\TcpdfNext\Core\Enums\EncryptionLevel;
use Yeeefang\TcpdfNext\Core\Enums\Permission;
use Yeeefang\TcpdfNext\Core\Config\EncryptionConfig;
use Yeeefang\TcpdfNext\Core\Config\FontConfig;
use Yeeefang\TcpdfNext\Core\ValueObjects\Margin;

$doc = Document::create(
    pageSize: PageSize::A4,
    orientation: Orientation::Portrait,
    unit: Unit::Millimeter,
);

// Margins
$doc->setMargins(new Margin(
    left: 15,
    top: 27,
    right: 15,
    bottom: 25,
));

// Fonts
$doc->configureFonts(function (FontConfig $config): void {
    $config->addDirectory('/path/to/fonts');
});

// Encryption
$doc->setEncryption(new EncryptionConfig(
    level: EncryptionLevel::AES256,
    userPassword: '',
    ownerPassword: 'secret',
    permissions: [Permission::Print],
));

// Accessibility
$doc->enableTaggedPdf();
$doc->setLanguage('en');

// Deterministic output (for tests)
// $doc->enableDeterministicMode();

// Metadata
$doc->setTitle('Company Report');
$doc->setAuthor('TCPDF-Next');
$doc->setSubject('Monthly Summary');
$doc->setKeywords('report, finance, 2026');

$doc->addPage();
$doc->cell(text: 'Hello, configured world!');
$doc->save('/tmp/configured.pdf');

Veröffentlicht unter der LGPL-3.0-or-later Lizenz.