Skip to content

PHP cookbook

This index lists the PHP-native NextPDF recipes: task-focused, runnable pages written directly against the core PHP API. The nextpdf core repository owns and verifies each recipe under docs/public/cookbook/php/. Each recipe has an examples/*.php script and a tests/Cookbook/Php/ harness test. The aggregator then pulls each page into this site and keeps its source provenance.

Because this page is an index, it does not make behavioral claims about any recipe. Each row records the recipe’s intent, the core module it uses, and its declared reproducibility profile. The profile and any conformance claim belong on the recipe page itself. They come from that page’s front-matter and its in-repo test, not from this index. For the integration (framework / renderer / service) cookbook, see Integration cookbook. For the contract every runnable recipe follows, see Recipe conventions.

Every [[…]] below is a forward reference to a page authored in the core repository under docs/public/cookbook/php/. The aggregator then pulls that page into this site. Each slug follows one convention: a single segment.

/cookbook/php/<recipe>/

<recipe> names the recipe’s intent in kebab-case (for example render-html-to-pdf, not the module name html). It is lowercase, hyphen-separated, has no version numbers, and ends in one trailing slash. Until a target page aggregates, its link is a placeholder and does not resolve. A recipe with no runnable example yet (the gap list below) cannot publish until its example and harness test exist, though the link already points to the final slug.

Each recipe declares the strictest profile it can honestly satisfy:

  • bitwise — byte-identical across runs (plain deterministic content with all entropy pinned).
  • structural — identical after normalising volatile atoms (the trailer /ID, creation/modification dates, font-subset prefixes — in practice, every multi-object PDF).
  • semantic — structural-AST plus metadata equivalence only (signed or timestamped output, or output whose equivalence is inherently non-byte-stable).

The recipe page proves the profile with its harness test. This index only reports the value that page declares.

The core repository already holds and merges these five recipes today: the Wave 8 set.

RecipeWhat it doesModuleProfile
sign-pades (planned upstream)Apply a CMS/PAdES baseline signature with a software keySecuritysemantic
encrypt-aes256 (planned upstream)Encrypt with AES-256 and set permission flagsSecuritystructural
pdfa4-conformance-gate (planned upstream)Produce PDF/A-4 output and gate on an external validatorConformancesemantic
accessible-pdfua2-from-html (planned upstream)Emit the tagged structure for accessible PDF/UA-2 authoringAccessibilitysemantic
validate-signature (planned upstream)Inspect whether a PDF carries a signature, and the trust boundaryInspectsemantic

Build, paginate, and style a document.

RecipeWhat it doesModuleProfile
render-html-to-pdf (planned upstream)Render an HTML document to PDFHtmlstructural
style-with-css (planned upstream)Apply CSS to an HTML renderHtmlstructural
html-table-layout (planned upstream)Lay out an HTML tableHtmlstructural
paginate-long-html (planned upstream)Paginate a long HTML documentHtmlstructural
compose-text-and-fonts (planned upstream)Compose text with typography controlTypographystructural
embed-and-subset-fonts (planned upstream)Embed and subset fontsFontstructural
cjk-vertical-writing (planned upstream)Set CJK text in vertical writing modeTypographystructural
multi-page-document (planned upstream)Build a multi-page documentDocumentstructural
headers-and-footers (planned upstream)Add running headers and footersLayoutstructural

Work with vectors, images, layers, and coordinate space.

RecipeWhat it doesModuleProfile
draw-vector-graphics (planned upstream)Draw vector graphicsGraphicsstructural
gradients-and-transparency (planned upstream)Apply gradients and transparencyGraphicsstructural
embed-images (planned upstream)Embed raster imagesContentstructural
optional-content-layers (planned upstream)Use optional content (layers)Graphicsstructural
transform-coordinate-space (planned upstream)Transform the coordinate spaceGraphicsstructural

Add bookmarks, links, annotations, and AcroForm fields.

RecipeWhat it doesModuleProfile
bookmarks-and-toc (planned upstream)Build bookmarks and a table of contentsNavigationstructural
links-and-annotations (planned upstream)Add links and annotationsNavigationstructural
generate-barcodes (planned upstream)Generate barcodesBarcodebitwise
fill-pdf-form (planned upstream)Fill an AcroFormFormstructural
flatten-form-fields (planned upstream)Flatten form fieldsFormstructural

Set metadata and viewer behavior.

RecipeWhat it doesModuleProfile
set-document-metadata (planned upstream)Set document metadataMetadatastructural
set-viewer-preferences (planned upstream)Set viewer preferencesDocumentstructural

Use encryption, signing, accessibility, and profile output. These recipes keep the support≠conformance and presence≠validity boundaries on the recipe page.

RecipeWhat it doesModuleProfile
encrypt-with-permissions (planned upstream)Encrypt with permission flagsSecuritystructural
sign-pades-b-b (planned upstream)Apply a PAdES signature (B-B and B-T)Securitysemantic
inspect-existing-signature (planned upstream)Inspect an existing signatureInspectsemantic
tagged-pdf-ua2 (planned upstream)Emit tagged structure for PDF/UA-2Accessibilitysemantic
pdf-a-4-output (planned upstream)Produce PDF/A-4 outputConformancesemantic
validate-conformance (planned upstream)Validate against a conformance profileCompliancesemantic

Read content and structure back out of a PDF.

RecipeWhat it doesModuleProfile
extract-text-content (planned upstream)Extract text contentTextsemantic
parse-and-inspect-pdf (planned upstream)Parse and inspect a PDFInspectsemantic
inspect-layout-boxes (planned upstream)Inspect layout boxesInspectsemantic

Use patterns that span several modules.

RecipeWhat it doesSpansProfile
worker-safe-batch-rendering (planned upstream)Render safely in a long-running worker (shared registries, bounded memory)Core · Performance · Supportsemantic
exception-aware-error-handling (planned upstream)Handle errors with the NextPDF exception hierarchyException · Contractsstructural
observe-with-opentelemetry (planned upstream)Observe rendering with OpenTelemetryObservability · Telemetry · Eventsemantic

These recipes need a new examples/*.php file plus a tests/Cookbook/Php/ harness in the core repository before they can publish. The slug above is final. The page remains a placeholder until the example lands and its test runs:

  • sign-pades-b-b (planned upstream) (covers PAdES B-B and B-T)
  • inspect-existing-signature (planned upstream)
  • extract-text-content (planned upstream)
  • parse-and-inspect-pdf (planned upstream)
  • validate-conformance (planned upstream)
  • inspect-layout-boxes (planned upstream)
  • worker-safe-batch-rendering (planned upstream) (example exists; new memory/GC harness test added)
  • observe-with-opentelemetry (planned upstream) (new PHP-native example added)

Every other recipe above already has a backing examples/*.php file and needs only a harness wrapper. This index records the slug and the eventual page. It does not claim that any pending page is already complete.