The margin parameter allows you to specify the spacing between the page edges and the content of your rendered document.

Overview

When generating PDFs or other documents, controlling the margins ensures proper spacing around your content. The margin parameter lets you define precise margins for all four sides of the document with support for different measurement units.

Parameter details

margin
object

Specifies the spacing between the page edges and the content of your rendered document

Usage

{
  "parts": "https://example.com",
  "margin": {
    "top": 10,
    "right": 10,
    "bottom": 10,
    "left": 10,
    "unit": "mm"
  }
}

Behavior

The margin parameter creates empty space around the content of your document. Each margin value must be a non-negative number (minimum: 0).

Use cases

This parameter is particularly useful for:

  1. Print-ready documents: Set appropriate margins for documents intended for printing.

  2. Professional reports: Create polished documents with consistent spacing around content.

  3. Custom layouts: Adjust margins to accommodate headers, footers, or binding space.

  4. Mobile-friendly PDFs: Optimize reading experience on smaller screens with appropriate margins.

Examples

Standard document margins

{
  "parts": "https://example.com",
  "margin": {
    "top": 25.4,
    "right": 25.4,
    "bottom": 25.4,
    "left": 25.4,
    "unit": "mm"
  }
}

Asymmetric margins for binding

{
  "parts": "https://example.com",
  "margin": {
    "top": 20,
    "right": 20,
    "bottom": 20,
    "left": 30,  // Wider left margin for binding
    "unit": "mm"
  }
}

Minimal margins

{
  "parts": "https://example.com",
  "margin": {
    "top": 5,
    "right": 5,
    "bottom": 5,
    "left": 5,
    "unit": "mm"
  }
}

Using different units

{
  "parts": "https://example.com",
  "margin": {
    "top": 1,
    "right": 1,
    "bottom": 1,
    "left": 1,
    "unit": "in"  // Inches
  }
}