Rendering options

The same options on every target: a JSON object for the API, the options field for WebAssembly, flags for the native binary. Most of the layout is decided by your CSS; options switch on what CSS cannot express.

Size and format

format is pdf, png, webp or svg. width and height are whole CSS pixels (96 per inch), from 1 to 32768.

CaseResult
Width onlyOne page or image, as wide as width (800 by default) and as tall as the content. The native binary always uses its --height (600 by default).
Width and heightOne page or image of exactly that size.
Height and paginationA PDF of several pages. @page { size } in the CSS overrides the size you pass; the height is still required.

Common paper sizes in CSS pixels:

PaperWidth × height
A4 (210 × 297 mm)794 × 1123
A5 (148 × 210 mm)559 × 794
US Letter (8.5 × 11 in)816 × 1056

PNG and WebP images have a transparent background unless the document paints one or backgroundColor is set.

Options

request body
{
  "html": "…",
  "format": "pdf",
  "width": 794,
  "height": 1123,
  "options": { "pagination": true, "pdfTitle": "Field Notes" }
}
OptionNative flagDescription
pagination--paginateBoolean. Paged PDF. Needs height and the PDF format. See pagination.
mediaType—"screen" (default) or "print": which @media rules apply. Paginating does not switch to print by itself.
pdfTitle, pdfAuthor--pdf-titlePDF metadata. The title is not taken from <title>, except in strict PDF/UA.
pdfLanguage--pdf-languageDocument language of the PDF, for instance "en".
pdfUa--pdf-uaBoolean. Strict PDF/UA-1.
pdfX--pdf-x"PDF/X-1a:2001", "PDF/X-3:2002" or "PDF/X-4". Print files.
pdfXOutputIntent--pdf-x-output-condition, --pdf-x-output-profile{ identifier, profile }: the printing condition and its ICC profile (a URL in the API, bytes in the package, a file for the binary).
linkedFootnotes--linked-footnotesBoolean. Turns notes referenced by role="doc-noteref" links (as pandoc writes them) into footnotes at their reference.
missingResources—"error" (default) fails the render when a resource cannot be loaded; "ignore" renders without it.
backgroundColor—Fills the background: "#fff", "#ffffff", "#ffffff80" or "rgba(255, 255, 255, 0.5)".
typographyseveralLine breaking and hyphenation. See typography.

An unknown value is refused before rendering: 422 from the API, a TypeError from the package, status 1 from the binary. A fuller example:

options
{
  "pagination": true,
  "pdfTitle": "Field Notes",
  "pdfAuthor": "Northwind Books",
  "mediaType": "print",
  "typography": {
    "justification": { "algorithm": "knuth-plass", "opticalMargins": true },
    "hyphenation": { "minWordLength": 8, "maxConsecutive": 2 }
  }
}

Pagination

With pagination, the document is split into pages and the CSS of paged media applies. The paper is described in the stylesheet, not in options:

@page {
  size: A4;                     /* or letter, A5 landscape, 148mm 210mm */
  margin: 20mm 18mm;
  @bottom-center { content: counter(page) " / " counter(pages); }
}
@page :first { margin-top: 60mm; }

h1 { break-before: page; }
figure, tr { break-inside: avoid; }
p { widows: 2; orphans: 2; }
  • @page size and margins, with :first, :left, :right, :blank and named pages.
  • The sixteen margin boxes (@top-center, @bottom-right…), with counter(page) and counter(pages).
  • Running headers with string-set and string(), or whole elements with position: running() and element().
  • Footnotes with float: footnote and the @footnote area.
  • Cross-references with target-counter() and target-text(), PDF bookmarks with bookmark-level, and a generated table of contents with data-palatine-toc.
  • break-before, break-after, break-inside, widows and orphans; table headers and footers repeat on each page.

The paginated report uses most of these. The paged media and footnotes and references articles explain them at length.

Page dimensions in the PDF

A PDF page measures one unit per CSS pixel. An A4 page is therefore 793.7 × 1122.5 units, where other tools write 595 × 842 points. Viewers and printers scale the page to the paper, and physical CSS lengths (mm, pt, in) keep their proportions on it. If a later step of your pipeline needs the page box in points, size the page in pixels:

/* A4 as 595 × 842 units; render with width 595 and height 842. */
@page { size: 595px 842px; margin: 54px; }
body { font-size: 10px; }

Typography

By default, lines are broken one at a time, as browsers do. Knuth–Plass composes each paragraph as a whole for even spacing and fewer hyphens; it applies to justified paragraphs. Hyphenation is requested in CSS and tuned in options.

html { hyphens: auto; }       /* with <html lang="en">, fr, de, es, it or pt */
p { text-align: justify; text-indent: 1.2em; margin: 0; }
options
{
  "typography": {
    "justification": {
      "algorithm": "knuth-plass",
      "opticalMargins": true,
      "wordSpacing": { "min": 0.8, "normal": 1, "max": 1.4 },
      "lastLine": { "minFill": 0.3, "penalty": 5000 }
    },
    "hyphenation": {
      "minWordLength": 6,
      "minBefore": 2,
      "minAfter": 3,
      "penalty": 50,
      "consecutivePenalty": 10000,
      "maxConsecutive": 2
    }
  }
}
OptionNative flagDescription
justification.algorithm--knuth-plass"greedy" (default) or "knuth-plass".
justification.opticalMargins--optical-marginsBoolean. Hangs punctuation slightly into the margin. Needs Knuth–Plass.
justification.wordSpacing--space-min, --space-normal, --space-maxFactors applied to the width of a space, with 0 ≤ min ≤ normal ≤ max ≤ 4. All three are required. Needs Knuth–Plass.
justification.lastLine--last-line-min, --last-line-penaltyDiscourages a last line shorter than minFill (0 to 1) with penalty (0 to 1000000). A preference, not a guarantee. Needs Knuth–Plass.
hyphenation.minWordLength--hyphen-min-wordShortest word that may be hyphenated, 6 to 128. Default 6.
hyphenation.minBefore, minAfter--hyphen-min-before, --hyphen-min-afterLetters kept before and after the break. Defaults 2 and 3.
hyphenation.penalty, consecutivePenalty--hyphen-penalty, --hyphen-consecutive-penaltyCost of a hyphen, and of hyphens on consecutive lines, for Knuth–Plass. Defaults 50 and 10000.
hyphenation.maxConsecutive--hyphen-max-consecutiveMost consecutive lines ending with a hyphen, 0 to 8. 0 forbids hyphens at line ends.
glyphScale--glyph-scaleFixed horizontal scale of glyphs, 0.98 to 1.02. Default 1.

The hyphenation options tune automatic hyphenation; they do not switch it on. That is the job of hyphens: auto and a lang attribute in English, French, German, Spanish, Italian or Portuguese. Soft hyphens (&shy;) work in every language. See the articles on Knuth–Plass line breaking and book typography.

PDF/X print files

Set pdfX for a file a printer's preflight can accept: "PDF/X-1a:2001" and "PDF/X-3:2002" (what print-on-demand services usually ask for) or "PDF/X-4". Every colour is written in gray or CMYK (black text prints with black ink only), pages are in points with a trim box, and the file names its printing condition. Without pdfXOutputIntent, PDF/X-1a and PDF/X-3 name CGATS TR 001 (SWOP). To name another condition, give its identifier; a condition outside the registered ones Palatine knows (CGATS TR 001, CGATS TR 006, FOGRA27, FOGRA39, FOGRA51, FOGRA52, JC200103) also needs its profile, the CMYK ICC profile your printer provides, which then converts the colours. PDF/X-4 always needs the profile. It cannot be combined with pdfUa.

How it works

  1. Colours become inks. A neutral colour is written as gray, so black text prints with black ink only. Every other colour is converted to CMYK, through your printer's ICC profile when you give one and by a plain formula otherwise. Images are converted the same way, and gradients are drawn as images first.
  2. The page is prepared for the press. Sizes are written in points with a trim box, fonts are embedded as subsets, and links are left out. Bookmarks are kept.
  3. Transparency is kept, flattened or refused. PDF/X-4 keeps it. PDF/X-1a and PDF/X-3 forbid it, so each translucent effect is either replaced by exactly what it shows or refused.
  4. The PDF/X label is written last. The identification and the printing condition are the last things written, and only when nothing was refused. A refused render never leaves a file or a stream that calls itself PDF/X.

In PDF/X-1a and PDF/X-3, these are flattened exactly:

  • translucent colours, text, images and boxes over a plain colour, such as the white page;
  • tinted boxes and boxes with a border;
  • a band or a logo over a single photo: that area becomes one opaque image at print resolution, and anything drawn on top stays as text and vectors.

PDF/X-1a and PDF/X-3 forbid transparency, and Palatine refuses rather than approximates. An effect over a single plain colour, or over plain colours and images only, is flattened into exactly what it shows; text is never turned into pixels. Anything else is refused with pdfx.transparency and a sentence that names the effect, the element and the page: remove the effect, or export as PDF/X-4, which allows transparency. Links are left out of PDF/X pages.

In PDF/X-1a and PDF/X-3, these are refused:

  • anything translucent over a gradient or a background image, which are neither plain colours nor images, and translucent text over an image;
  • anything translucent over a shape that is not a one-colour rectangle or an image (a stroke, a circle, a path);
  • translucent text whose glyphs overlap other glyphs or each other: a text shadow under translucent text, negative letter-spacing, a line-height smaller than the glyphs;
  • a translucent (rgba) link or translucent underlined text whose underline crosses the letters, which in practice means any text with descenders (g, j, p, q, y): "the guide" is refused, "docs" is accepted; and any translucent underline or line-through that touches the ink of the text, at any thickness. Use an opaque colour for the link, remove the underline, or export as PDF/X-4;
  • translucent Arabic text from about 22 px;
  • many small translucent shapes of one colour that stack or touch, such as the dots of an SVG scatter plot;
  • a translucent inline background split across lines when it has a border, or, with box-decoration-break: clone, when it reaches the text of the line above;
  • filters, masks and blend modes;
  • colour emoji (glyphs drawn as images);
  • translucent content near the corners of a rounded box;
  • translucent borders with a radius around a background, and translucent borders of a collapsed table where they meet other borders;
  • a border or text over the background of an opacity group placed on an image;
  • very dense pages, where what lies behind a translucent effect cannot be worked out in bounded time and memory.

Overlaps are judged on glyph outlines, not boxes, so kerning, accents and close lines stay accepted. One tolerance, in two cases only: between glyphs of one translucent text run, and between straight-line pieces of the same ink (the pieces of one underline), an overlap smaller than one square CSS pixel and smaller than a quarter of either piece, such as where the Arabic letters of a word join at text sizes, is drawn in the text's own tint, where an ordinary PDF, compositing the same translucent ink twice, makes it slightly darker. It never excuses a whole small shape, any shape that is neither a glyph nor a straight line, or text against another text draw, even of its own colour: those overlaps are refused. Each flattened region is limited in size (2 million pixels, nearly an A4 page at 150 dpi; 4 million on a page), and flattened pages make much larger files. Gray is written as black ink only and is not converted through the profile. Under WASI, the memory of the flattening is not measured and is bounded by fixed limits only. No reference preflight (a printer's, callas pdfToolbox, Acrobat) has validated these files yet: have your printer check one before relying on it.

request body
{
  "html": "<html lang='en'><head><title>My Novel</title></head><body>…</body></html>",
  "css": "@page { size: 6in 9in; margin: 0.75in }",
  "format": "pdf",
  "width": 600,
  "height": 800,
  "options": {
    "pagination": true,
    "pdfX": "PDF/X-4",
    "pdfXOutputIntent": {
      "identifier": "FOGRA39",
      "profile": "https://example.com/profiles/coated-fogra39.icc"
    }
  }
}

The profile is fetched like an image: from resources (base64, within the 6 MiB request) or from its URL, counted in the resource budget. A refusal answers 422 with the code and the sentence in the JSON body.

Palatine checks its PDF/X files with its own structural checks; no reference preflight has validated them yet. See the details and limitations.

Strict PDF/UA-1

Set pdfUa for a tagged, accessible PDF. Strict mode requires a document title and language, meaningful image alternatives, a consistent heading hierarchy, table headers and named links. Unsupported content or incomplete prerequisites produce no PDF and an accessibility.* code that names the problem. The default PDF mode is unaffected.

request body
{
  "html": "<html lang='en'><head><title>Report</title></head><body><h1>Report</h1><p>Annual results.</p></body></html>",
  "format": "pdf",
  "width": 600,
  "height": 800,
  "options": { "pdfUa": true, "pagination": true }
}

A refusal answers 422 with the code in the JSON body.

The strict mode supports a defined subset of HTML and CSS. Forms, SVG, ruby and unsupported visual effects are refused. It renders the complete source under the memory ceiling; a document that cannot fit returns memory.limit. Authors must review reading order, descriptions, table meaning, language changes and contrast, then check the document with their target assistive technology. Automated validation cannot judge that meaning. See the supported inputs, checks and limitations.

Warnings

When the engine meets something it cannot lay out as specified, it falls back, finishes the document and reports a warning. A warning has a stable code, a message for humans, and the element concerned when known:

{
  "code": "pagination.monolithic-overflow",
  "message": "Unbreakable content taller than the page area is sliced at the page edge",
  "source": "img#chart"
}
const header = response.headers.get("x-palatine-warnings");
const warnings = header ? JSON.parse(decodeURIComponent(header)) : [];
CodeMeaning
pagination.monolithic-overflowUnbreakable content, such as an image, is taller than a page and was sliced at the page edge.
pagination.unsupported-table-fragmentationA table that could not be split is taller than a page.
pagination.unsupported-float, -position, -transform, -writing-mode, -negative-margin, -layoutA box in a context that cannot be split across pages was kept whole, moved to the next page or sliced.
pagination.unsupported-page-name, -page-widthA named page or a page of a different width was ignored.
pagination.footnote-*A footnote could not be placed as specified.
pagination.running-contextA running element could not be taken out of its context.
crossref.missing-targetA link or target-counter() points to an id that does not exist.
memory.unboundedA long document was rendered in one piece, so its memory grows with its length.
license-expiredLicensed builds only: the license has expired and rendering will stop at the end of the grace period.

Treat a warning as a prompt to look at the page concerned. Codes are stable; messages may be reworded.