Trang (HasPages)
Thêm trang
php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\ValueObjects\PageSize;
use Yeeefang\TcpdfNext\Contracts\Orientation;
$pdf = Document::create()
->addPage() // A4 dọc (mặc định)
->addPage(PageSize::Letter()) // US Letter
->addPage(PageSize::A3(), Orientation::Landscape) // A3 ngang
->addPage(PageSize::Legal()); // US LegalKích thước trang
PageSize là value object final readonly với factory method:
ISO 216 Series A
A0(), A1(), A2(), A3(), A4(), A5(), A6()
ISO 216 Series B
B0(), B1(), B2(), B3(), B4(), B5()
Bắc Mỹ
Letter(), Legal(), Tabloid()
Kích thước tùy chỉnh
php
// Chiều rộng và cao tính bằng point (1 pt = 1/72 inch)
$custom = new PageSize(400.0, 600.0, 'custom');
// Hoặc từ chuỗi tên
$a4 = PageSize::fromName('A4');Chuyển hướng
php
$landscape = PageSize::A4()->landscape();
$portrait = PageSize::A4()->portrait();Margin
php
use Yeeefang\TcpdfNext\ValueObjects\Margin;
$pdf->setMargins(Margin::symmetric(15.0, 10.0)) // 15mm dọc, 10mm ngang
->setLeftMargin(20.0)
->setTopMargin(25.0)
->setRightMargin(20.0);Factory method:
Margin::uniform(10.0)— 10mm tất cả cạnhMargin::symmetric(15.0, 10.0)— dọc 15mm, ngang 10mmMargin::zero()— không marginnew Margin(top, right, bottom, left)— chỉ định rõ
Auto Page Break
php
$pdf->setAutoPageBreak(true, 20); // Ngắt cách đáy 20mm
$pdf->setAutoPageBreak(false); // TắtKhi bật, nội dung vượt quá trang tự động kích hoạt addPage().
Vị trí
php
$pdf->setX(50.0); // Đặt vị trí ngang
$pdf->setY(100.0); // Đặt vị trí dọc
$pdf->setXY(50.0, 100.0); // Đặt cả hai
$x = $pdf->getX();
$y = $pdf->getY();
$width = $pdf->getPageWidth();
$height = $pdf->getPageHeight();
$margins = $pdf->getMargins(); // Trả về đối tượng MarginThao tác trang
php
$pdf->movePage(3, 1); // Di chuyển trang 3 đến vị trí 1
$pdf->copyPage(2); // Nhân đôi trang 2
$pdf->deletePage(4); // Xóa trang 4Nhóm trang
Nhóm trang để đánh số trang độc lập (ví dụ: theo chương):
php
$pdf->startPageGroup();
$groupPageNo = $pdf->getGroupPageNo();Vùng trang
Định nghĩa vùng hình chữ nhật mà nội dung nên tránh:
php
$pdf->addPageRegion(10, 10, 50, 50); // x, y, chiều rộng, chiều cao
$regions = $pdf->getPageRegions();
$pdf->removePageRegion(0);
$pdf->setPageRegions($regions);Thông tin trang
php
$currentPage = $pdf->getPage(); // Index trang hiện tại
$totalPages = $pdf->getNumPages(); // Tổng số trang