The parts parameter allows you to define the content sources that will be rendered into your PDF document.

Overview

When generating a PDF, you need to specify what content to render. The parts parameter accepts an array of content sources, which can be URLs, HTML strings, or structured content objects. These sources are rendered sequentially into a single PDF document.

Parameter details

parts
array
required

Defines the content sources that will be rendered into your PDF document

Min items: 1

Max items: 50

Item types: URL string, HTML string, or content object

Usage

{
  "parts": [
    "https://example.com",
    "<h1>Hello World</h1>",
    {
      "type": "html",
      "content": "<div>Structured HTML content</div>"
    },
    {
      "type": "template",
      "content": {
        "template_id": "invoice_template",
        "context": {
          "customer_name": "Acme Inc."
        }
      }
    }
  ]
}

Behavior

The parts parameter accepts three types of content:

  1. URL strings: Publicly accessible URLs that return HTML content.
  2. HTML strings: Raw HTML content that starts with a valid HTML tag.
  3. Content objects: Structured objects with type and content fields. The content object can be:
    • URL content with type: "url"
    • HTML content with type: "html"
    • Template content with type: "template" (see the Templates page for details)

Each content part is rendered sequentially in the order provided, creating a multi-page PDF where each part typically starts on a new page.

Use cases

This parameter is particularly useful for:

  1. Multi-source documents: Combine content from multiple webpages into a single PDF.

  2. Mixed content types: Blend web content with custom HTML in the same document.

  3. Report generation: Create comprehensive reports by combining dynamic web content with static templates.

  4. Document assembly: Build documents from multiple components stored in different locations.

  5. Dynamic content injection: Use templates with context data to generate personalized documents.

Examples

Single URL

{
  "parts": ["https://example.com"]
}

Multiple URLs

{
  "parts": [
    "https://example.com/cover",
    "https://example.com/chapter1",
    "https://example.com/chapter2"
  ]
}

Mixing URLs and HTML

{
  "parts": [
    "https://example.com/header",
    "<h1>Custom Content</h1><p>This is inserted between web pages.</p>",
    "https://example.com/footer"
  ]
}

Using structured content objects

{
  "parts": [
    {
      "type": "url",
      "content": "https://example.com"
    },
    {
      "type": "html",
      "content": "<div>Custom HTML content</div>"
    },
    {
      "type": "template",
      "content": {
        "template_id": "invoice_template",
        "context": {
          "customer_name": "Acme Inc.",
          "invoice_number": "INV-2023-001"
        }
      }
    }
  ]
}

For more details on using templates, see the Templates documentation.