그래픽 (HasDrawing)
HasDrawing 트레이트는 선, 사각형, 원, 다각형, 곡선, 화살표, 파이 섹터를 위한 벡터 드로잉 프리미티브를 제공합니다. 모든 메서드는 static을 반환하므로 모든 호출을 체이닝할 수 있습니다.
빠른 참조
| 메서드 | 도형 |
|---|---|
line() | 두 점 사이의 직선 |
rect() | 사각형 |
roundedRect() | 둥근 모서리 사각형 |
circle() | 원 |
ellipse() | 타원 |
polygon() | 점 배열에서의 임의의 다각형 |
regularPolygon() | 정다각형 (n변) |
starPolygon() | 별 모양 |
arrow() | 머리가 있는 화살표 |
pieSector() | 차트용 파이 섹터 |
curve() | 3차 베지어 곡선 |
polyCurve() | 다중 세그먼트 베지어 곡선 |
기본 예제
use Yeeefang\TcpdfNext\Core\Document;
$pdf = Document::create()
->addPage()
->setDrawColor(255, 0, 0)
->setFillColor(200, 220, 255)
->line(10, 10, 100, 10)
->rect(10, 20, 80, 40, 'DF')
->roundedRect(10, 70, 80, 40, 5, 'DF')
->circle(150, 40, 30, 'DF')
->ellipse(150, 100, 40, 20, 'DF')
->arrow(10, 140, 100, 140)
->regularPolygon(150, 160, 25, 6, 'DF')
->starPolygon(50, 200, 25, 5, 3, 'DF');스타일 매개변수
대부분의 드로잉 메서드는 렌더링을 제어하는 $style 문자열을 받습니다:
| 값 | 의미 |
|---|---|
S | 선(윤곽선만) — 기본값 |
F | 채우기만 |
DF 또는 B | 그리기 및 채우기 (양쪽 모두) |
선 및 사각형
$pdf->line(float $x1, float $y1, float $x2, float $y2);
$pdf->rect(float $x, float $y, float $w, float $h, string $style = '');
$pdf->roundedRect(float $x, float $y, float $w, float $h, float $r, string $style = '');line()은 점 (x1, y1)에서 (x2, y2)까지 그립니다. rect()는 표준 사각형을 그립니다. roundedRect()는 반지름 $r의 둥근 모서리를 추가합니다.
원 및 타원
$pdf->circle(float $x0, float $y0, float $r, string $style = '');
$pdf->ellipse(float $x0, float $y0, float $rx, float $ry, string $style = '');circle()은 중심점과 반지름을 받습니다. ellipse()는 수평 및 수직 반지름을 별도로 사용합니다.
다각형
$pdf->polygon(array $points, string $style = '');
$pdf->regularPolygon(float $x0, float $y0, float $r, int $ns, string $style = '');
$pdf->starPolygon(float $x0, float $y0, float $r, int $nv, int $ng, string $style = '');polygon()은 좌표의 플랫 배열 [x1, y1, x2, y2, ...]을 받습니다. regularPolygon()은 반지름 $r의 원에 내접하는 n변 다각형을 그립니다. starPolygon()은 $nv개의 꼭짓점과 갭 팩터 $ng를 가진 별을 그립니다.
화살표 및 파이 섹터
$pdf->arrow(float $x0, float $y0, float $x1, float $y1);
$pdf->pieSector(float $xc, float $yc, float $r, float $a, float $b, string $style = '');arrow()는 목적지에 화살표 머리가 있는 선을 그립니다. pieSector()는 각도 $a에서 $b(도 단위)까지의 파이 섹터를 그리며, 차트에 유용합니다:
$pdf->setFillColor(255, 100, 100)->pieSector(100, 100, 40, 0, 120, 'F')
->setFillColor(100, 255, 100)->pieSector(100, 100, 40, 120, 250, 'F')
->setFillColor(100, 100, 255)->pieSector(100, 100, 40, 250, 360, 'F');베지어 곡선
$pdf->curve(float $x0, float $y0, float $x1, float $y1, float $x2, float $y2, float $x3, float $y3);
$pdf->polyCurve(array $points);curve()는 (x0, y0)에서 (x3, y3)까지 제어점 (x1, y1)과 (x2, y2)를 가진 3차 베지어를 그립니다. polyCurve()는 점 배열에서 여러 베지어 세그먼트를 연결합니다.
선 스타일
$pdf->setLineStyle(array $style);$style 배열은 다음 키를 지원합니다: width(float), cap(butt, round, square), join(miter, round, bevel), dash(문자열 또는 배열 패턴), color(RGB 배열).
$pdf->setLineStyle([
'width' => 0.5,
'cap' => 'round',
'join' => 'round',
'dash' => '3,2',
'color' => [0, 0, 200],
])->line(10, 10, 190, 10);크롭 및 레지스트레이션 마크
전문 출력을 위한 인쇄 준비 마크를 추가합니다:
$pdf->cropMark(20, 20, 10, 10)
->registrationMark(105, 10)
->colorRegistrationBar(20, 280, 170, 5);