跳到內容

NextPDF Symfony 套件設定

套件的所有行為都透過 config/packages/nextpdf.yaml 中的 nextpdf 根鍵設定。每個鍵都有預設值,因此組態皆為選用。本頁內容與 Configuration.php 完全一致。

結構描述由 NextPDF\Symfony\DependencyInjection\Configuration 定義。無效值會在容器建構時觸發 Symfony 的 InvalidConfigurationException,使建構失敗。

型別預設值驗證
page_formatenumA4下列其中之一:A4A3A5LetterLegalTabloid
orientationenumP下列其中之一:PL
unitenummm下列其中之一:ptmmcmin
pdfa純量null下列其中之一:null44e4f
fonts_path純量%kernel.project_dir%/resources/fonts
cache_path純量%kernel.cache_dir%/nextpdf
image_cache_mb整數50最小值 0
font_cache_lockingbooleantrue
preload_fonts字串清單[]
型別預設值
icc_profile.rgb純量null
icc_profile.cmyk純量null

會套用到 PdfFactory 產生的每一份文件。

型別預設值
defaults.creator純量NextPDF
defaults.author純量(空)
defaults.language純量en
defaults.margin_topfloat10.0
defaults.margin_rightfloat10.0
defaults.margin_bottomfloat10.0
defaults.margin_leftfloat10.0
defaults.font_family純量dejavusans
defaults.font_sizefloat12.0
defaults.trim_box變數null
defaults.bleed_box變數null

PdfFactory 會從此區段讀取 creatorauthorlanguage,並套用到每一份新建立的文件。其餘鍵會儲存為容器參數,供引擎使用。

只有偵測到已安裝 nextpdf/artisan 時才會生效。

型別預設值
artisan.chrome_binary純量null
artisan.render_timeout整數30
artisan.default_css純量(空)
artisan.no_sandboxbooleanfalse
artisan.max_html_size整數5000000

只有在已安裝 nextpdf/premium 時才會生效。同時使用此套件與 Pro 版本時,支援的簽章組態為 baseline B-B 設定檔。level 節點接受下列字串值,以維持與更廣泛 NextPDF 組態家族的結構描述相容性。此套件實際提供的簽章能力是 B-B。B-B 以外的設定檔另見 NextPDF Premium 文件;本頁不主張此套件提供那些能力。

型別預設值驗證
signature.enabledbooleanfalse
signature.certificate純量null
signature.private_key純量null
signature.password純量(空)
signature.extra_certs字串清單[]
signature.levelenumB-B接受的集合:B-BB-TB-LTB-LTA(實際提供 B-B;B-T/B-LT/B-LTA 是結構描述相容性的值,並非實際提供的 Pro 能力)

只有當 signature.enabled 為 true signature.certificate 已設定時,編譯器階段才會註冊簽署器服務;否則此區段不會產生作用。

Time Stamp Authority(時戳機構)用戶端組態;設定後供 Pro 簽章使用。

型別預設值
tsa.url純量null
tsa.username純量(空)
tsa.password純量(空)
tsa.cert純量null
tsa.key純量null
tsa.timeout整數30
tsa.allow_insecure_httpbooleanfalse
tsa.pinned_public_keys字串清單[]
tsa.warn_on_key_rotationbooleantrue

只有設定 tsa.url 時,才會註冊 TSA 用戶端服務。

型別預設值
ocsp_cache.enabledbooleantrue
ocsp_cache.ttl整數86400
ocsp_cache.directory純量null

非同步產生作業的調節選項,會在已安裝 symfony/messenger 時生效。

型別預設值
messenger.transport純量async
messenger.timeout整數120
messenger.retries整數3

以下組態檔列出每個區段及其預設值:

nextpdf:
page_format: A4
orientation: P
unit: mm
pdfa: ~
fonts_path: '%kernel.project_dir%/resources/fonts'
cache_path: '%kernel.cache_dir%/nextpdf'
image_cache_mb: 50
font_cache_locking: true
preload_fonts: []
icc_profile:
rgb: ~
cmyk: ~
defaults:
creator: NextPDF
author: ''
language: en
margin_top: 10.0
margin_right: 10.0
margin_bottom: 10.0
margin_left: 10.0
font_family: dejavusans
font_size: 12.0
trim_box: ~
bleed_box: ~
artisan:
chrome_binary: ~
render_timeout: 30
default_css: ''
no_sandbox: false
max_html_size: 5000000
signature:
enabled: false
certificate: ~
private_key: ~
password: ''
extra_certs: []
level: B-B
tsa:
url: ~
username: ''
password: ''
cert: ~
key: ~
timeout: 30
allow_insecure_http: false
pinned_public_keys: []
warn_on_key_rotation: true
ocsp_cache:
enabled: true
ttl: 86400
directory: ~
messenger:
transport: async
timeout: 120
retries: 3

此套件會從 config/services.php 載入服務定義。下表完整反映該檔案內容。

服務 ID共用公開備註
NextPDF\Typography\FontRegistrynextpdf.fonts_path 建構;可選的 PSR-3 記錄器
NextPDF\Contracts\FontRegistryInterface(別名)別名為 FontRegistry
NextPDF\Graphics\ImageRegistry有界 LRU;標記為 kernel.resetreset
NextPDF\Core\DocumentFactory共用這兩個登錄表
NextPDF\Contracts\DocumentFactoryInterface(別名)別名為 DocumentFactory
NextPDF\Symfony\Service\PdfFactory讀取 defaultspdfaartisan 參數
NextPDF\Contracts\PdfDocumentInterface工廠 [PdfFactory, create]
NextPDF\Core\Document(別名)別名為 PdfDocumentInterface
nextpdf.document(別名)別名為 PdfDocumentInterface
NextPDF\Symfony\Http\PdfResponse無狀態輔助元件

此套件也會註冊 EInvoice 合約繫結(EmbedderInterfaceValidatorInterfaceProfileInterfaceSchematronRunnerInterface),但只有對應的 Premium 實作類別存在時才會註冊。每個繫結都註冊為非共用,因此呼叫端會取得全新的實例。每次呼叫的剖析器狀態絕不會外洩到其他請求。

nextpdf.document(及其別名)為非共用:每次容器 resolve(解析)時,都會回傳不同的文件。根據 PSR-11,容器允許以相同識別碼在連續的 get() 呼叫中回傳不同的值(PSR-11 §1.1.2)。字型登錄表為共用,並在暖機後鎖定。因此,結構性字型資料在每個程序中只會剖析一次,且無法在請求進行期間變更。

其中的 FontRegistryImageRegistry 服務接受一個可選的 Psr\Log\LoggerInterface,並以 nullOnInvalid() 繫結。記錄器是可替換、可選的協作元件,與 PSR-3 記錄器合約一致(PSR-3)。

PdfFactoryPdfResponse、文件工廠介面與字型登錄表介面都是公開服務。可從容器取得它們,也可在自動繫結的控制器與服務中透過型別提示注入。建議的進入點是以建構式注入 NextPDF\Symfony\Service\PdfFactory

  • 未安裝 Pro 卻設定了 pdfa——會儲存該值但加以忽略。PdfFactory 只有在編譯時偵測到 Pro 擴充功能時才會套用 PDF/A。
  • image_cache_mb: 0——有效,且會停用影像 LRU 快取。負值會在建構時被拒絕。
  • 設定了 signature.enabled: true 卻沒有 signature.certificate——不會註冊簽署器服務;此組態依設計會靜默不生效。
  • %kernel.*% placeholder(佔位符)——fonts_pathcache_path 的預設值使用 Symfony 容器參數;只有需要字面路徑時,才改用絕對路徑覆寫。

表格每列都是本頁提出的一項規範性主張,並釘選到受管 SDO 語料庫提供的完整 64 位元組十六進位 reference_id。provenance(來源資訊:語料庫資訊清單、檢索傳輸)位於 _sidecars/rag-citations.yaml

規範條款參考 ID主張
PSR-11psr_11_container#1.1.2.p3.bget() 每次解析可能回傳不同的值
PSR-3psr_3_logger#x3.p17可選的 LoggerInterface 協作元件

signature 與 tsa 區段只有在已安裝 nextpdf/premium(Pro)時才會生效。這是可選的 Pro 能力;本頁所說明的 Core 套件無須變更程式碼即可採用。請參閱 </get-license/?intent=symfony-pro>。

  • /integrations/symfony/install/ — 安裝並註冊此套件。
  • /integrations/symfony/overview/ — 能力摘要。
  • /integrations/symfony/production-usage/ — worker 安全性與非同步模式。
  • /integrations/symfony/boot-and-discovery/ — 組態如何在開機期間解析。