Skip to content
getnextpdf.com

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 recipe is authored in the core repository under docs/public/cookbook/php/ and published into this site by the aggregator. 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.

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.

Build, paginate, and style a document.

RecipeWhat it doesModuleProfile
render-html-to-pdfRender an HTML document to PDFHtmlstructural
style-with-cssApply CSS to an HTML renderHtmlstructural
html-table-layoutLay out an HTML tableHtmlstructural
paginate-long-htmlPaginate a long HTML documentHtmlstructural
paginate-large-html-tablesPaginate a large HTML table across pagesHtmlstructural
render-rtl-arabic-htmlRender right-to-left Arabic HTMLHtmlstructural
compose-text-and-fontsCompose text with typography controlTypographystructural
embed-and-subset-fontsEmbed and subset fontsFontstructural
cjk-vertical-writingSet CJK text in vertical writing modeTypographystructural
multi-page-documentBuild a multi-page documentDocumentstructural
headers-and-footersAdd running headers and footersLayoutstructural

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

RecipeWhat it doesModuleProfile
draw-vector-graphicsDraw vector graphicsGraphicsstructural
gradients-and-transparencyApply gradients and transparencyGraphicsstructural
embed-imagesEmbed raster imagesContentstructural
add-watermarks-and-backgroundsAdd text and image watermarks or backgrounds to pagesContentstructural
cmyk-spot-color-and-icc-profilesProduce print-ready CMYK and spot colorColorstructural
embed-file-attachmentsEmbed files and create PDF portfoliosContentstructural
optional-content-layersUse optional content (layers)Graphicsstructural
transform-coordinate-spaceTransform the coordinate spaceGraphicsstructural

Add bookmarks, links, annotations, and AcroForm fields.

RecipeWhat it doesModuleProfile
bookmarks-and-tocBuild bookmarks and a table of contentsNavigationstructural
generate-dynamic-table-of-contentsGenerate a dynamic table of contentsNavigationstructural
links-and-annotationsAdd links and annotationsNavigationstructural
generate-barcodesGenerate barcodesBarcodebitwise
gs1-composite-barcodesGenerate GS1 Composite barcodes (CC-C carrier)Barcodestructural
fill-pdf-formFill an AcroFormFormstructural
flatten-form-fieldsFlatten form fieldsFormstructural
form-field-validation-and-flatten-with-stateValidate form fields and flatten with stateFormstructural

Set metadata and viewer behavior.

RecipeWhat it doesModuleProfile
set-document-metadataSet document metadataMetadatastructural
set-viewer-preferencesSet viewer preferencesDocumentstructural

Assemble, split, and optimize existing documents.

RecipeWhat it doesModuleProfile
merge-external-pdfsMerge external PDFs or append pagesDocumentstructural
split-and-extract-pagesSplit a PDF and extract page rangesDocumentstructural
optimize-pdf-file-sizeReduce PDF file size with compression and subsettingDocumentstructural

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-aes256Encrypt with AES-256 and set permission flagsSecuritystructural
encrypt-with-permissionsEncrypt with permission flagsSecuritystructural
sign-pades-b-bApply a PAdES signature (B-B and B-T)Securitysemantic
inspect-existing-signatureInspect an existing signatureInspectsemantic
tagged-pdf-ua2Emit tagged structure for PDF/UA-2Accessibilitysemantic
accessible-pdfua2-from-htmlEmit the tagged structure for accessible PDF/UA-2 authoring from HTMLAccessibilitysemantic
pdf-a-4-outputProduce PDF/A-4 outputConformancesemantic
pdfa4-conformance-gateProduce PDF/A-4 output and gate on an external validatorConformancesemantic
validate-conformanceValidate against a conformance profileCompliancesemantic

Read content and structure back out of a PDF.

RecipeWhat it doesModuleProfile
extract-text-contentExtract text contentTextsemantic
multilingual-copy-paste-extractionMake CJK and Arabic PDFs copy-paste correctTextstructural
parse-and-inspect-pdfParse and inspect a PDFInspectsemantic
inspect-layout-boxesInspect layout boxesInspectsemantic

Use patterns that span several modules.

RecipeWhat it doesSpansProfile
worker-safe-batch-renderingRender safely in a long-running worker (shared registries, bounded memory)Core · Performance · Supportsemantic
streaming-and-memoryProfile streaming and memory usagePerformancebitwise
exception-aware-error-handlingHandle errors with the NextPDF exception hierarchyException · Contractsstructural
custom-error-recovery-patternsImplement custom error recovery and retry strategiesExceptionsemantic
observe-with-opentelemetryObserve rendering with OpenTelemetryObservability · Telemetry · Eventsemantic

Every recipe above is published with a backing examples/*.php script and a tests/Cookbook/Php/ harness test in the core repository. When a new recipe is authored upstream, it appears here once its example and test land.