PDFCraft
Render option

Control the page margins of a PDF

Page margins. Any side may be omitted; omitted sides default to 0.

Fieldoptions.margin
Typeobject: top, right, bottom, left
Defaultnone

Fields

FieldTypeWhat it does
topCSS length — "20mm", "1in", "72px"e.g. "20mm", "1in", "72px".
rightCSS length — "20mm", "1in", "72px"e.g. "15mm".
bottomCSS length — "20mm", "1in", "72px"e.g. "20mm".
leftCSS length — "20mm", "1in", "72px"e.g. "15mm".

What it is for

Margins on all four sides, in any CSS length — mm, in, px, pt. Any side may be omitted and defaults to 0.

The trap

headerHtml and footerHtml are drawn INSIDE the margin. A header with no top margin has nowhere to go and silently does not appear — this is the single most common "my header does not work" cause. Give it at least 20mm.

Example

curl -X POST https://api.pdfcraft.dev/v1/render \
  -H "Authorization: Bearer $PDFCRAFT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>hello</h1>",
    "options": {
      "margin": {
        "top": "20mm",
        "right": "15mm",
        "bottom": "20mm",
        "left": "15mm"
      }
    }
  }' \
  --output out.pdf

Every option

Try any of these in the playground without writing a line of code, or read the full reference.