Value Objects API
All value objects in TCPDF-Next are immutable. Every "modifier" method returns a new instance, leaving the original unchanged. This eliminates a category of bugs caused by shared mutable state.
PageSize
Namespace: TcpdfNext\ValueObjects\PageSize
Represents the dimensions of a page. Internally all measurements are stored in PDF points (1/72 inch).
Factory Methods (ISO A Series)
Factory Methods (ISO B Series)
Factory Methods (North American)
Custom & Lookup
Orientation Helpers
Properties
| Property | Type | Description |
|---|---|---|
$width | float | Width in points |
$height | float | Height in points |
$name | string | Human-readable name (e.g., 'A4', 'Letter') |
Convenience Methods
Example
use TcpdfNext\ValueObjects\PageSize;
$a4 = PageSize::a4();
$landscape = $a4->landscape(); // 297 x 210 mm
$custom = PageSize::fromMm(140, 216, 'Half Letter');
$letter = PageSize::fromName('Letter');Margin
Namespace: TcpdfNext\ValueObjects\Margin
Represents four-sided page margins. Internal storage is in PDF points.
Factory Methods
Properties
| Property | Type | Description |
|---|---|---|
$top | float | Top margin in points |
$right | float | Right margin in points |
$bottom | float | Bottom margin in points |
$left | float | Left margin in points |
Modifier Methods
Calculation Methods
Example
use TcpdfNext\ValueObjects\Margin;
use TcpdfNext\ValueObjects\PageSize;
$margin = Margin::mm(top: 15, right: 20, bottom: 15, left: 20);
$narrow = $margin->withLeft(36.0)->withRight(36.0);
$area = $margin->printableArea(PageSize::a4());
echo $area->widthMm(); // 170.0Position
Namespace: TcpdfNext\ValueObjects\Position
An immutable x--y coordinate pair in PDF points.
Factory Methods
Properties
| Property | Type | Description |
|---|---|---|
$x | float | Horizontal coordinate in points |
$y | float | Vertical coordinate in points |
Methods
Example
use TcpdfNext\ValueObjects\Position;
$pos = Position::mm(x: 25.4, y: 50.8);
$shifted = $pos->translate(dx: 10, dy: 20);
echo $shifted->xMm(); // ~28.9Dimension
Namespace: TcpdfNext\ValueObjects\Dimension
An immutable width--height pair in PDF points.
Factory Methods
Properties
| Property | Type | Description |
|---|---|---|
$width | float | Width in points |
$height | float | Height in points |
Methods
Example
use TcpdfNext\ValueObjects\Dimension;
$dim = Dimension::mm(width: 210, height: 297);
echo $dim->width; // 595.28
echo $dim->widthMm(); // 210.0
$swapped = $dim->swap(); // 297 x 210 mm equivalentUnit
Namespace: TcpdfNext\ValueObjects\Unit
Static utility class for converting between measurement units. All conversions are based on the PDF standard of 72 points per inch.
Conversion Methods
Example
use TcpdfNext\ValueObjects\Unit;
$points = Unit::mmToPoints(210.0); // 595.28
$mm = Unit::pointsToMm(595.28); // 210.0
$points = Unit::inchesToPoints(8.5); // 612.0
$result = Unit::convert(1.0, 'in', 'mm'); // 25.4Color
Namespace: TcpdfNext\Graphics\Color
Immutable color representation supporting multiple color spaces. Although Color lives in the Graphics package, it is used pervasively across the library (text color, draw color, fill color, bookmark color, annotation color).
Factory Methods
Properties
| Property | Type | Description |
|---|---|---|
$space | ColorSpace | The color space enum (DeviceRGB, DeviceCMYK, DeviceGray, Separation) |
Methods
Example
use TcpdfNext\Graphics\Color;
$brand = Color::hex('#0066CC');
$print = Color::cmyk(100, 0, 0, 0);
$spot = Color::spot('PANTONE 286 C', Color::cmyk(100, 66, 0, 2));
$faded = $brand->withAlpha(0.5);
echo $brand->toHex(); // '0066cc'See Also
- API Overview -- All packages at a glance
- Document API -- Methods that accept these value objects
- Enums Reference -- ColorSpace, Orientation, and other related enums
- Value Objects Guide -- Conceptual overview and advanced patterns