PDF Options

Complete guide to PDF generation options.

PDF Options

All PDF generation endpoints accept an options object to customize the output. This guide covers all available options in detail.


Paper Format

The format option sets the paper size. Default is A4.

FormatDimensionsUse Case
A4210 × 297 mmStandard documents (EU)
Letter8.5 × 11 inStandard documents (US)
A3297 × 420 mmPosters, large documents
A5148 × 210 mmBooklets, small documents
Legal8.5 × 14 inLegal documents (US)
Tabloid11 × 17 inNewspapers, large spreads
{
  "options": {
    "format": "Letter"
  }
}

Custom Size

For custom paper sizes, use width and height instead of format:

{
  "options": {
    "width": "6in",
    "height": "9in"
  }
}

Orientation

Set landscape: true for landscape orientation:

{
  "options": {
    "format": "A4",
    "landscape": true
  }
}
OrientationA4 DimensionsLetter Dimensions
Portrait210 × 297 mm8.5 × 11 in
Landscape297 × 210 mm11 × 8.5 in

Margins

Set page margins using the margin object. Accepts CSS units: mm, cm, in, px.

{
  "options": {
    "margin": {
      "top": "25mm",
      "bottom": "25mm",
      "left": "20mm",
      "right": "20mm"
    }
  }
}

Common Margin Presets

PresetTop/BottomLeft/RightTotal Width
Normal25mm20mm170mm
Narrow12.7mm12.7mm185mm
Wide25.4mm50.8mm108mm
None0mm0mm210mm

Headers and footers require sufficient margins. Recommended minimum: 15mm top/bottom.


Scale

Adjust the rendering scale with scale. Range: 0.1 to 2.0 (default: 1.0).

{
  "options": {
    "scale": 0.8
  }
}
ScaleEffect
0.550% - Fit more content
1.0100% - Default
1.5150% - Larger text/images
2.0200% - Maximum zoom

Background

Control background rendering with print_background:

{
  "options": {
    "print_background": true
  }
}
ValueEffect
trueInclude background colors and images (default)
falseWhite background only

Headers and Footers

Add custom headers and footers using HTML:

{
  "options": {
    "header": "<div style='font-size: 10px; text-align: center; width: 100%;'>My Document</div>",
    "footer": "<div style='font-size: 10px; text-align: center; width: 100%;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
    "margin": {
      "top": "40mm",
      "bottom": "30mm"
    }
  }
}

Available Variables

Use these CSS classes in your header/footer HTML:

ClassValue
pageNumberCurrent page number
totalPagesTotal page count
dateCurrent date (formatted)
titleDocument title
urlSource URL (URL to PDF only)

Example: Professional Header/Footer

{
  "options": {
    "header": "<div style='width: 100%; padding: 0 20mm; font-size: 9px; color: #666; display: flex; justify-content: space-between;'><span>Company Name</span><span>Confidential</span></div>",
    "footer": "<div style='width: 100%; padding: 0 20mm; font-size: 9px; color: #666; display: flex; justify-content: space-between;'><span>Generated: <span class='date'></span></span><span>Page <span class='pageNumber'></span> of <span class='totalPages'></span></span></div>",
    "margin": {
      "top": "35mm",
      "bottom": "25mm"
    }
  }
}

Wait Time (URL to PDF)

For pages with dynamic content, use wait_for to wait before capturing:

{
  "url": "https://example.com/dashboard",
  "options": {
    "wait_for": 3000
  }
}
ValueDescription
0No wait (default)
10001 second
50005 seconds
3000030 seconds (maximum)

Viewport (URL to PDF)

Set the browser viewport size for rendering:

{
  "options": {
    "viewport": {
      "width": 1920,
      "height": 1080
    }
  }
}
DeviceWidthHeight
Desktop HD19201080
Desktop1440900
Laptop1366768
Tablet1024768
Mobile390844

Full Page (URL to PDF)

Capture the entire scrollable page:

{
  "options": {
    "full_page": true
  }
}

This may result in multi-page PDFs for long pages.


Complete Example

{
  "markdown": "# Report\n\nContent here...",
  "theme": "corporate",
  "options": {
    "format": "A4",
    "landscape": false,
    "margin": {
      "top": "35mm",
      "bottom": "25mm",
      "left": "20mm",
      "right": "20mm"
    },
    "scale": 1.0,
    "print_background": true,
    "header": "<div style='font-size: 9px; text-align: center; width: 100%;'>Monthly Report - January 2025</div>",
    "footer": "<div style='font-size: 9px; text-align: center; width: 100%;'>Page <span class='pageNumber'></span></div>"
  }
}