Ga naar hoofdinhoud

Print Functionality

DocuDesk provides a dedicated print pipeline for generating browser-ready print previews and PDF/A-3b compliant archival documents from Twig/HTML templates. All rendering happens server-side using mPDF with bundled DejaVu Sans fonts.

Overview

The print feature supports two workflows:

  1. Print preview — Renders the template to HTML and injects print-optimized CSS so the browser can print a pixel-perfect page.
  2. PDF/A-3b download — Generates an archival-quality PDF with embedded fonts, XMP metadata, and PDF/A-3b compliance enforced by mPDF.

Templates can be referenced by a stored template UUID (via the Template Management feature) or provided as inline Twig/HTML content in the request body.

API Endpoints

POST /apps/docudesk/api/print/preview

Returns rendered HTML with print-optimized CSS injected. Intended for use in a preview iframe before the user commits to a download.

Request body (JSON):

FieldTypeRequiredDescription
templateIdstring*UUID of a stored template (see Template Management)
templatestring*Inline Twig/HTML template content
dataobjectData context passed to Twig for rendering
optionsobjectPDF options: format, orientation

One of templateId or template is required.

Successful response (200):

{
"html": "<style>...</style><h1>Hello World</h1>",
"title": "My Document"
}

Error response:

{ "error": "Either templateId or template content is required" }

PDF/A Download

POST /apps/docudesk/api/print/pdf-a

Returns a PDF/A-3b binary as a file download. PDF/A mode is always enabled for this endpoint.

Request body (JSON):

FieldTypeRequiredDescription
templateIdstring*UUID of a stored template
templatestring*Inline Twig/HTML template content
dataobjectData context passed to Twig
filenamestringSuggested download filename (default: document.pdf)

One of templateId or template is required.

Successful response (200):

  • Content-Type: application/pdf
  • Content-Disposition: attachment; filename="<filename>"
  • Body: PDF/A-3b binary

Configuration Options

The options object (used in the print preview endpoint and stored template records) accepts:

KeyTypeDefaultDescription
formatstringA4Page size: A4, A3, Letter, Legal
orientationstringPP (portrait) or L (landscape)
marginobject15mmOverride margins: { top, right, bottom, left } (mm)
titlestring""PDF metadata title field
pdfabooleanfalseForce PDF/A-3b mode (always true for /pdf-a)

Template Resolution

When templateId is supplied, the format and orientation are read from the stored template record fields (format, orientation). Inline request options are ignored for stored templates.

When template (inline content) is supplied, options from the request body are used directly.

PDF/A-3b Compliance

The PDF/A-3b output includes:

  • Embedded fonts — DejaVu Sans (Regular, Bold, Italic, Bold Italic) bundled with the app
  • XMP metadata — Author (DocuDesk), creator (DocuDesk PDF/A Generator), and title
  • Print CSS — Automatic @page size, margin normalization, and page-break rules
  • PDFAauto — mPDF auto-corrects non-compliant elements where possible

Dependencies

DependencyPurpose
mpdf/mpdfHTML-to-PDF conversion
TemplateRendererTwig sandboxed template engine
TemplateServiceStored template retrieval (optional)

Services

PdfService

Handles all PDF generation logic.

MethodDescription
renderPdf()Render Twig template to PDF binary
renderHtmlPreview()Render Twig template to HTML with print CSS
buildPrintCss()Generate @media print style block for given format/orientation

PrintController

REST controller for print endpoints. Resolves template content from request parameters and delegates to PdfService.

MethodRouteVerb
preview()/api/print/previewPOST
downloadPdfA()/api/print/pdf-aPOST