Skip to content

페이지 (HasPages)

페이지 추가

php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\ValueObjects\PageSize;
use Yeeefang\TcpdfNext\Contracts\Orientation;

$pdf = Document::create()
    ->addPage()                                          // A4 세로 (기본값)
    ->addPage(PageSize::Letter())                        // US Letter
    ->addPage(PageSize::A3(), Orientation::Landscape)    // A3 가로
    ->addPage(PageSize::Legal());                        // US Legal

페이지 크기

PageSize는 팩토리 메서드를 가진 final readonly 값 객체입니다:

ISO 216 A 시리즈

A0(), A1(), A2(), A3(), A4(), A5(), A6()

ISO 216 B 시리즈

B0(), B1(), B2(), B3(), B4(), B5()

북미 규격

Letter(), Legal(), Tabloid()

사용자 정의 크기

php
// 너비와 높이는 포인트 단위 (1 pt = 1/72 인치)
$custom = new PageSize(400.0, 600.0, 'custom');

// 또는 이름 문자열로부터
$a4 = PageSize::fromName('A4');

방향 전환

php
$landscape = PageSize::A4()->landscape();
$portrait = PageSize::A4()->portrait();

여백

php
use Yeeefang\TcpdfNext\ValueObjects\Margin;

$pdf->setMargins(Margin::symmetric(15.0, 10.0))  // 상하 15mm, 좌우 10mm
    ->setLeftMargin(20.0)
    ->setTopMargin(25.0)
    ->setRightMargin(20.0);

팩토리 메서드:

  • Margin::uniform(10.0) — 모든 면 10mm
  • Margin::symmetric(15.0, 10.0) — 상하 15mm, 좌우 10mm
  • Margin::zero() — 여백 없음
  • new Margin(top, right, bottom, left) — 명시적 지정

자동 페이지 넘김

php
$pdf->setAutoPageBreak(true, 20);  // 하단 20mm에서 페이지 넘김
$pdf->setAutoPageBreak(false);      // 비활성화

활성화되면 페이지를 넘어가는 콘텐츠가 자동으로 addPage()를 트리거합니다.

위치

php
$pdf->setX(50.0);          // 수평 위치 설정
$pdf->setY(100.0);         // 수직 위치 설정
$pdf->setXY(50.0, 100.0);  // 양쪽 모두 설정

$x = $pdf->getX();
$y = $pdf->getY();
$width = $pdf->getPageWidth();
$height = $pdf->getPageHeight();
$margins = $pdf->getMargins();  // Margin 객체 반환

페이지 조작

php
$pdf->movePage(3, 1);   // 페이지 3을 위치 1로 이동
$pdf->copyPage(2);      // 페이지 2 복제
$pdf->deletePage(4);    // 페이지 4 제거

페이지 그룹

독립적인 페이지 번호 매기기(예: 장별)를 위해 페이지를 그룹화합니다:

php
$pdf->startPageGroup();
$groupPageNo = $pdf->getGroupPageNo();

페이지 영역

콘텐츠가 피해야 할 사각 영역을 정의합니다:

php
$pdf->addPageRegion(10, 10, 50, 50);  // x, y, 너비, 높이

$regions = $pdf->getPageRegions();
$pdf->removePageRegion(0);
$pdf->setPageRegions($regions);

페이지 정보

php
$currentPage = $pdf->getPage();       // 현재 페이지 인덱스
$totalPages = $pdf->getNumPages();    // 전체 페이지 수

LGPL-3.0-or-later 라이선스로 배포됩니다.