The size parameter allows you to control the dimensions of the generated PDF document.

Overview

When rendering a PDF, you can specify the page size either by using standard paper size presets (like A4, Letter) or by defining custom dimensions with a specific unit of measurement.

Parameter details

size
object
default:{"preset":"a4"}

Controls the dimensions of the generated PDF document

Usage

Using a preset:

{
  "parts": "https://example.com",
  "size": {
    "preset": "a4"
  }
}

Using custom dimensions:

{
  "parts": "https://example.com",
  "size": {
    "width": 210,
    "height": 297,
    "unit": "mm"
  }
}

Behavior

  • When using a preset, any provided width and height values are ignored.
  • The preset property takes precedence over custom dimensions if both are provided.
  • If neither preset nor custom dimensions are specified, the default A4 size is used.

Available presets

The following standard paper size presets are available:

PresetSize (mm)Size (inches)
a0841 × 118933.1 × 46.8
a1594 × 84123.4 × 33.1
a2420 × 59416.5 × 23.4
a3297 × 42011.7 × 16.5
a4210 × 2978.3 × 11.7
a5148 × 2105.8 × 8.3
a6105 × 1484.1 × 5.8
a774 × 1052.9 × 4.1
a852 × 742.0 × 2.9
a937 × 521.5 × 2.0
a1026 × 371.0 × 1.5
letter216 × 2798.5 × 11.0
legal216 × 3568.5 × 14.0
tabloid279 × 43211.0 × 17.0
ledger432 × 27917.0 × 11.0

Use cases

This parameter is particularly useful for:

  1. Standardized documents: Use presets like a4 or letter for documents that need to conform to standard paper sizes.

  2. Custom publications: Create custom-sized documents for specialized publications like brochures, cards, or posters.

  3. Print-ready output: Ensure your PDFs match the exact dimensions required by your printing service.

Example

Creating a business card-sized PDF:

{
  "parts": "<div style='text-align: center;'><h2>John Doe</h2><p>Software Engineer</p><p>john@example.com</p></div>",
  "size": {
    "width": 3.5,
    "height": 2,
    "unit": "in"
  }
}

Note: For responsive web content, you may want to use the prefer_css_page_size parameter in conjunction with size to control how content is scaled to fit the page.