Table of contents
Options that used to be documented as “magic strings” — page units, conformance modes, alignment codes, blend modes, barcode types, filter names, signature profiles — are now also available as backed enums. The enums make the accepted values discoverable from the IDE and checkable by static analysis, without breaking any existing code.
The enum-with-union-type Pattern
Every affected parameter is declared as a string|Enum union, and the backing value of each enum case is exactly the string that was accepted before:
enum Unit: string
{
case Point = 'pt';
case Millimeter = 'mm';
case Centimeter = 'cm';
case Inch = 'in';
}
That means the two calls below are equivalent, and a codebase can migrate one call site at a time:
use Com\Tecnick\Pdf\Page\Unit;
$pdf = new \Com\Tecnick\Pdf\Tcpdf(unit: 'mm');
$pdf = new \Com\Tecnick\Pdf\Tcpdf(unit: Unit::Millimeter);
Where an option is passed inside a configuration array rather than as a typed parameter (for example the signature()->configure() options), the array still carries strings: use Enum::Case->value to reference them symbolically.
tc-lib-pdf
| Enum | Values | Used for |
|---|---|---|
\Com\Tecnick\Pdf\PdfConformance | '', pdfa1, pdfa1a, pdfa1b, pdfa2, pdfa2a, pdfa2b, pdfa2u, pdfa3, pdfa3a, pdfa3b, pdfa3u, pdfx, pdfx1a, pdfx3, pdfx4, pdfx5, pdfua, pdfua1, pdfua2 | The mode constructor argument. See /docs/standards/. |
\Com\Tecnick\Pdf\TextHAlign | L, C, R, J | Horizontal text alignment in cells. |
\Com\Tecnick\Pdf\TextVAlign | T, C, B, A, L, D | Vertical text alignment in cells (top, center, bottom, ascent, baseline, descent). |
\Com\Tecnick\Pdf\TextFitMode | '', T, S, F | Overflow handling: off, truncate, stretch, shrink font. |
\Com\Tecnick\Pdf\DisplayZoom | fullpage, fullwidth, real, default | Viewer zoom preference. |
\Com\Tecnick\Pdf\AFRelationship | Source, Data, Alternative, Supplement, Unspecified | Embedded-file relationship (Factur-X / ZUGFeRD). |
\Com\Tecnick\Pdf\Cache\CacheType | font, image | Cacheable subsystems. See /docs/cache/. |
\Com\Tecnick\Pdf\Signature\SignatureAppearanceMode | N, R, D | Signature appearance stream (normal, rollover, down). |
\Com\Tecnick\Pdf\Signature\ExternalSignatureEncoding | binary, base64, hex | Payload encoding for external/HSM signing. |
Text direction is expressed with \Com\Tecnick\Unicode\TextDirection ('' auto, R, L), accepted by the forcedir argument of the text methods.
Companion Packages
| Package | Enums |
|---|---|
| tc-lib-pdf-page | Unit, Orientation, PageBoxType, PageLayout, PageDisplayMode, TransparencyGroupMode |
| tc-lib-pdf-graph | BlendMode, PathPaintOp |
| tc-lib-pdf-font | FontType |
| tc-lib-pdf-filter | FilterType |
| tc-lib-pdf-sign | SignatureProfile, DigestAlgorithm |
| tc-lib-color | ColorModelType |
| tc-lib-barcode | BarcodeType, QrEccLevel, QrEncodingMode, DatamatrixShape, DatamatrixEncoding, AztecHint, AztecRange |
| tc-lib-unicode | TextDirection |
| tc-lib-unicode-data | BidiClass |
Example
use Com\Tecnick\Barcode\BarcodeType;
use Com\Tecnick\Pdf\PdfConformance;
use Com\Tecnick\Pdf\TextHAlign;
use Com\Tecnick\Pdf\TextVAlign;
use Com\Tecnick\Pdf\Page\Unit;
$pdf = new \Com\Tecnick\Pdf\Tcpdf(
unit: Unit::Millimeter,
mode: PdfConformance::Pdfua1,
);
$pdf->addTextCell(
txt: 'Hello, PDF!',
posx: 15,
posy: 20,
width: 90,
height: 10,
valign: TextVAlign::Center,
halign: TextHAlign::Left,
);
$barcode = new \Com\Tecnick\Barcode\Barcode();
$bobj = $barcode->getBarcodeObj(BarcodeType::QRCODE, 'https://tcpdf.org');
Migration Guidance
- No migration is required: string arguments remain supported and are not deprecated.
- Prefer enums for new code and for options with a small closed set of values; they turn a typo into a compile-time or static-analysis error instead of a runtime exception.
- When comparing a stored option against an enum, compare the backing values (
$mode === PdfConformance::Pdfua1->value), because the libraries normalize typed parameters to their string form internally.
Related Guides
- Standards and conformance modes: /docs/standards/
- Digital signature profiles and digests: /docs/digital-signatures/
- Optional external cache and cache types: /docs/cache/
- Generated API reference: /docs/srcdoc/tc-lib-pdf
Previous: /docs/development/
Overview: /docs/
Next: /docs/remote-resources/