Laravel 패키지
Laravel · LGPL-3.0Laravel 패키지(yeeefang/tcpdf-nextlaravel)는 다음과 같은 Laravel 12 최우선 통합을 제공합니다:
- 자동 검색 ServiceProvider -- DI 바인딩, Octane 안전 스코프 서비스
Pdf파사드 -- 편리한 정적 접근PdfResponse-- 안전한 HTTP 응답 헬퍼 (인라인/다운로드)GeneratePdfJob-- 큐 기반 비동기 PDF 생성
설치
bash
composer require yeeefang/tcpdf-nextlaravel요구 사항: Laravel ^12.0
ServiceProvider는 자동 검색됩니다. 설정 파일을 퍼블리시합니다:
bash
php artisan vendor:publish --tag=tcpdf-next-config빠른 시작
php
use Yeeefang\TcpdfNext\Laravel\Facades\Pdf;
use Yeeefang\TcpdfNext\Laravel\Http\PdfResponse;
class InvoiceController extends Controller
{
public function download(Invoice $invoice)
{
$pdf = Pdf::create()
->setTitle("Invoice #{$invoice->number}")
->addPage()
->setFont('DejaVuSans', '', 12)
->cell(0, 10, "Invoice #{$invoice->number}");
return PdfResponse::download($pdf, "invoice-{$invoice->number}.pdf");
}
}서비스 프로바이더 바인딩
| 인터페이스 | 바인딩 | 스코프 |
|---|---|---|
PdfDocumentInterface | Document::create() | 팩토리 (해석 시마다 새로 생성) |
FontManagerInterface | FontManager | 스코프 (요청마다 새로 생성, Octane 안전) |
SignerInterface | config/tcpdf-next.php에서 구성 | 팩토리 |
TcpdfServiceProvider는 제공된 설정 파일의 합리적인 기본값을 병합하고 애플리케이션이 부팅되기 전에 모든 바인딩을 등록합니다. Laravel Octane 환경에서는 요청 간 상태 누출을 방지하기 위해 스코프 바인딩이 자동으로 플러시됩니다.
패키지 구조
Yeeefang\TcpdfNext\Laravel\
├── TcpdfServiceProvider # DI 바인딩, 설정 퍼블리싱
├── Facades\
│ └── Pdf # Document 팩토리에 대한 정적 프록시
├── Http\
│ └── PdfResponse # 인라인 / 다운로드 응답 헬퍼
└── Jobs\
└── GeneratePdfJob # 큐 가능한 비동기 PDF 생성의존성 주입
파사드 대신 계약을 직접 주입합니다:
php
use Yeeefang\TcpdfNext\Contracts\PdfDocumentInterface;
class ReportService
{
public function __construct(
private readonly PdfDocumentInterface $pdf,
) {}
public function generate(array $data): string
{
return $this->pdf
->addPage()
->setFont('Helvetica', 'B', 16)
->cell(0, 10, 'Monthly Report')
->setFont('Helvetica', '', 12)
->cell(0, 10, "Generated: " . now()->format('F j, Y'))
->output();
}
}