내비게이션 (HasNavigation)
HasNavigation 트레이트와 그 하위 모듈(BookmarkManager, TocManager, AnnotationManager, FileAttachment)은 PDF 내비게이션 기능을 제공합니다: 계층적 북마크, 자동 생성 목차, 내부 및 외부 링크, 명명된 목적지, 주석, 임베디드 파일 첨부. 모든 메서드는 static을 반환하므로 모든 호출을 체이닝할 수 있습니다.
빠른 참조
| 메서드 | 기능 |
|---|---|
bookmark() | 계층적 북마크 / 아웃라인 항목 추가 |
addTOC() | 점선 리더가 있는 목차 자동 생성 |
addHTMLTOC() | HTML 스타일 목차 |
addLink() | 내부 링크 목적지 생성 (링크 ID 반환) |
setLink() | 내부 링크 대상 위치 설정 |
setDestination() | 명명된 목적지 앵커 생성 |
annotation() | 텍스트 주석 추가 |
addFileAttachment() | PDF에 파일 첨부 임베딩 |
기본 예제
php
use Yeeefang\TcpdfNext\Core\Document;
$pdf = Document::create()
->addPage()
->setFont('Helvetica', '', 12)
// 북마크
->bookmark('Chapter 1', 0)
->cell(0, 10, 'Chapter 1: Introduction', newLine: true)
->bookmark('Section 1.1', 1)
->cell(0, 10, '1.1 Getting Started', newLine: true)
// 내부 링크
->addPage()
->bookmark('Chapter 2', 0)
->cell(0, 10, 'Chapter 2: Advanced Topics', newLine: true)
// 파일 첨부
->addFileAttachment('/path/to/data.xlsx', 'data.xlsx', 'Supporting data')
// 마지막에 목차 자동 생성 (페이지 1에 삽입)
->addTOC(1, ' . ', 'Table of Contents');1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
북마크 / 아웃라인
php
$pdf->bookmark(string $txt, int $level = 0, float $y = -1, int $page = -1, string $style = '', array $color = []);1
북마크는 PDF 리더의 아웃라인 패널에 나타납니다. $level을 증가시켜 중첩합니다.
목차
php
$pdf->addTOC(int $page, string $numberSuffix = '', string $bookmarkText = '');1
모든 북마크가 추가된 후에 addTOC()를 호출하십시오. 목차는 북마크 트리에서 구축되어 지정된 페이지 위치에 삽입됩니다. 항목 스타일링에 대한 완전한 제어를 위해 HTML과 CSS를 사용하는 addHTMLTOC()를 사용하십시오.
내부 링크
페이지 간 클릭 가능한 상호 참조를 생성합니다:
php
use Yeeefang\TcpdfNext\Core\Document;
$pdf = Document::create()
->addPage()
->setFont('Helvetica', '', 12);
$linkId = $pdf->addLink();
$pdf->write(10, 'Jump to Chapter 2', link: $linkId)
->addPage()
->setLink($linkId, y: 0)
->cell(0, 10, 'Chapter 2 starts here', newLine: true);1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
외부 링크
cell(), write() 또는 image()의 $link 매개변수에 URL 문자열을 전달합니다:
php
$pdf->cell(0, 10, 'Visit our website', link: 'https://example.com', newLine: true)
->write(10, 'Click here', link: 'https://docs.example.com');1
2
2
명명된 목적지
php
$pdf->setDestination(string $name, float $y = -1, int $page = -1);1
명명된 목적지를 사용하면 외부 문서나 URL이 #name 프래그먼트를 통해 특정 위치에 링크할 수 있습니다.
주석
php
$pdf->annotation(float $x, float $y, float $w, float $h, string $text, array $opt = []);1
주석은 PDF 뷰어에서 스티키 노트 아이콘으로 나타납니다.
php
$pdf->annotation(50, 80, 10, 10, 'Review this section before release.', [
'subtype' => 'Text',
'icon' => 'Comment',
'color' => [255, 255, 0],
]);1
2
3
4
5
2
3
4
5
파일 첨부
php
$pdf->addFileAttachment(string $file, string $name, string $desc);1
임베디드 파일은 PDF 리더의 첨부 패널에 나타납니다.
php
$pdf->addFileAttachment('/reports/q4-data.xlsx', 'q4-data.xlsx', 'Q4 financial data')
->addFileAttachment('/reports/methodology.pdf', 'methodology.pdf', 'Research methodology');1
2
2