Pages (HasPages)
Adding Pages
php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\ValueObjects\PageSize;
use Yeeefang\TcpdfNext\Contracts\Orientation;
$pdf = Document::create()
->addPage() // A4 Portrait (default)
->addPage(PageSize::Letter()) // US Letter
->addPage(PageSize::A3(), Orientation::Landscape) // A3 Landscape
->addPage(PageSize::Legal()); // US LegalPage Sizes
PageSize is a final readonly value object with factory methods:
ISO 216 A Series
A0(), A1(), A2(), A3(), A4(), A5(), A6()
ISO 216 B Series
B0(), B1(), B2(), B3(), B4(), B5()
North American
Letter(), Legal(), Tabloid()
Custom Size
php
// Width and height in points (1 pt = 1/72 inch)
$custom = new PageSize(400.0, 600.0, 'custom');
// Or from a name string
$a4 = PageSize::fromName('A4');Orientation Switching
php
$landscape = PageSize::A4()->landscape();
$portrait = PageSize::A4()->portrait();Margins
php
use Yeeefang\TcpdfNext\ValueObjects\Margin;
$pdf->setMargins(Margin::symmetric(15.0, 10.0)) // 15mm vertical, 10mm horizontal
->setLeftMargin(20.0)
->setTopMargin(25.0)
->setRightMargin(20.0);Factory methods:
Margin::uniform(10.0)— 10mm all sidesMargin::symmetric(15.0, 10.0)— vertical 15mm, horizontal 10mmMargin::zero()— no marginsnew Margin(top, right, bottom, left)— explicit
Auto Page Break
php
$pdf->setAutoPageBreak(true, 20); // Break 20mm from bottom
$pdf->setAutoPageBreak(false); // DisableWhen enabled, content that would overflow the page automatically triggers addPage().
Position
php
$pdf->setX(50.0); // Set horizontal position
$pdf->setY(100.0); // Set vertical position
$pdf->setXY(50.0, 100.0); // Set both
$x = $pdf->getX();
$y = $pdf->getY();
$width = $pdf->getPageWidth();
$height = $pdf->getPageHeight();
$margins = $pdf->getMargins(); // Returns Margin objectPage Manipulation
php
$pdf->movePage(3, 1); // Move page 3 to position 1
$pdf->copyPage(2); // Duplicate page 2
$pdf->deletePage(4); // Remove page 4Page Groups
Group pages for independent page numbering (e.g., per-chapter):
php
$pdf->startPageGroup();
$groupPageNo = $pdf->getGroupPageNo();Page Regions
Define rectangular regions that content should avoid:
php
$pdf->addPageRegion(10, 10, 50, 50); // x, y, width, height
$regions = $pdf->getPageRegions();
$pdf->removePageRegion(0);
$pdf->setPageRegions($regions);Page Info
php
$currentPage = $pdf->getPage(); // Current page index
$totalPages = $pdf->getNumPages(); // Total page count