Bỏ qua để đến nội dung

Tích hợp NextPDF Artisan

nextpdf/artisan là thư viện, không phải plugin của framework. Để tích hợp, hãy cài đặt nó, gắn ChromeRendererConfig vào một tài liệu NextPDF, rồi gọi writeHtmlChrome(). Dùng trang này để tìm các phần tài liệu Artisan còn lại.

Terminal window
composer require nextpdf/artisan

Để xem đầy đủ ma trận yêu cầu và các phụ thuộc Chrome bên ngoài, hãy xem /integrations/artisan/install/.

Artisan không đi kèm service provider, bundle hay manifest tự động khám phá của framework. Đây là thư viện PHP Standard Recommendation 4 (PSR-4) thuần (NextPDF\Artisan\, NextPDF\Parser\) mà bạn sử dụng trực tiếp. Vì vậy không có gì cần khám phá. Điểm truy cập là phương thức writeHtmlChrome(), do nextpdf/core cung cấp trên Document sau khi các lớp cầu nối có thể được tự động nạp. Để xem mô hình khám phá và khởi động, hãy xem /integrations/artisan/boot-and-discovery/.

Không có tích hợp container nào cần công bố. Trong các môi trường không có container dependency injection, EInvoiceServiceFactory cung cấp các phương thức factory tĩnh (makeEmbedder, makeValidator, makeDefaultProfile, makeSchematronRunner). Các phương thức này trả về các bản triển khai contract e-invoice của Premium, hoặc null khi gói Premium chưa được cài đặt. Điều này phản ánh hành vi trả về null của các gói wrapper framework, nên code không có container vẫn dùng cùng một bề mặt API. Để xem chi tiết và lý do, hãy xem /integrations/artisan/boot-and-discovery/.

Điểm truy cậpỞ đâuĐược ghi chép tại
Document::writeHtmlChrome() (phương thức core)nextpdf/core/integrations/artisan/quickstart/
Document::setChromeRendererConfig() (phương thức core)nextpdf/core/integrations/artisan/quickstart/
ChromeHtmlRenderer::render()nextpdf/artisan/integrations/artisan/production-usage/
ChromeRendererConfig / ::fromArray()nextpdf/artisan/integrations/artisan/configuration/
EInvoiceServiceFactory::make*()nextpdf/artisan/integrations/artisan/boot-and-discovery/

Chữ ký của writeHtmlChrome()(string $html, ?float $width = null, ?float $height = null): static, đã được xác minh từ nextpdf/coresrc/Core/Concerns/HasTextOutput.php.

<?php
declare(strict_types=1);
use NextPDF\Artisan\ChromeHtmlRenderer;
use NextPDF\Artisan\ChromeRendererConfig;
require __DIR__ . '/vendor/autoload.php';
$renderer = new ChromeHtmlRenderer(new ChromeRendererConfig());
assert($renderer->getHtmlSecurityPolicy()->getName() === 'default');
echo "ARTISAN_WIRED\n";

Điều này chứng minh rằng việc tự động nạp và các liên kết contract của nextpdf/core có thể phân giải mà không cần khởi chạy Chrome (hành vi được xác nhận bởi tests/Unit/Artisan/ChromeHtmlRendererTest.php::usesDefaultHtmlSecurityPolicyWhenNoneInjected). Để xem smoke test kết xuất đầu cuối có chạy Chrome, hãy xem /integrations/artisan/chrome-renderer-setup/.

  • Kết xuất tài liệu đầu tiên của bạn: /integrations/artisan/quickstart/
  • Tất cả tùy chọn cấu hình: /integrations/artisan/configuration/
  • Cung cấp Chrome / container: /integrations/artisan/chrome-renderer-setup/
  • Mô hình truyền tải và cô lập: /integrations/artisan/security-and-operations/
  • Kết nối cho production và batch worker: /integrations/artisan/production-usage/
  • Chẩn đoán lỗi: /integrations/artisan/troubleshooting/
  • Cách gói được khởi động: /integrations/artisan/boot-and-discovery/

Cầu nối là phần mềm mã nguồn mở đầy đủ chức năng. Các gói Premium bổ sung tính năng nhúng e-invoice (Pro) và xác thực (Enterprise) trên tệp Portable Document Format (PDF) đã kết xuất. Khi các gói này không có mặt, EInvoiceServiceFactory chuyển về null, nên bạn có thể viết code tích hợp một lần và chạy nó dù có hay không có Premium.

  • /integrations/artisan/overview/
  • /integrations/artisan/install/
  • /integrations/artisan/boot-and-discovery/
  • /integrations/artisan/quickstart/