> ## Documentation Index
> Fetch the complete documentation index at: https://genui.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PDF Template

> Generate downloadable PDF documents

The `pdf` template generates a PDF document from HTML or Markdown content.

## Content Schema

<ParamField body="content.html" type="string">
  HTML content to render as PDF
</ParamField>

<ParamField body="content.markdown" type="string">
  Markdown content to render as PDF (alternative to HTML)
</ParamField>

<ParamField body="content.css" type="string">
  Custom CSS styles for the PDF
</ParamField>

<ParamField body="content.pageSize" type="string">
  Page size: `a4`, `letter`, `legal` (default: `a4`)
</ParamField>

<ParamField body="content.orientation" type="string">
  Page orientation: `portrait`, `landscape` (default: `portrait`)
</ParamField>

<ParamField body="content.margins" type="object">
  Page margins with `top`, `right`, `bottom`, `left` in pixels
</ParamField>

<Note>
  Provide either `html` or `markdown`, not both. If both are provided, `html` takes precedence.
</Note>

## Example: HTML to PDF

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://genui.sh/api/artifacts \
    -H "Authorization: Bearer $GENUI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "template": "pdf",
      "title": "Invoice #1234",
      "content": {
        "html": "<h1>Invoice #1234</h1><p>Date: January 15, 2024</p><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>$5,000</td></tr><tr><td>Development</td><td>$10,000</td></tr></table><p><strong>Total: $15,000</strong></p>",
        "css": "body { font-family: Arial; } table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid #ddd; padding: 8px; }",
        "pageSize": "letter",
        "margins": {"top": 50, "right": 50, "bottom": 50, "left": 50}
      }
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://genui.sh/api/artifacts",
      headers={"Authorization": f"Bearer {GENUI_API_KEY}"},
      json={
          "template": "pdf",
          "title": "Invoice #1234",
          "content": {
              "html": """
                  <h1>Invoice #1234</h1>
                  <p>Date: January 15, 2024</p>
                  <table>
                      <tr><th>Item</th><th>Amount</th></tr>
                      <tr><td>Consulting</td><td>$5,000</td></tr>
                      <tr><td>Development</td><td>$10,000</td></tr>
                  </table>
                  <p><strong>Total: $15,000</strong></p>
              """,
              "css": "body { font-family: Arial; } table { width: 100%; }",
              "pageSize": "letter"
          }
      }
  )
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://genui.sh/api/artifacts', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${GENUI_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      template: 'pdf',
      title: 'Invoice #1234',
      content: {
        html: `
          <h1>Invoice #1234</h1>
          <p>Date: January 15, 2024</p>
          <table>
            <tr><th>Item</th><th>Amount</th></tr>
            <tr><td>Consulting</td><td>$5,000</td></tr>
            <tr><td>Development</td><td>$10,000</td></tr>
          </table>
          <p><strong>Total: $15,000</strong></p>
        `,
        css: 'body { font-family: Arial; } table { width: 100%; }',
        pageSize: 'letter'
      }
    })
  });
  ```

  ```go Go theme={null}
  payload := map[string]interface{}{
      "template": "pdf",
      "title":    "Invoice #1234",
      "content": map[string]interface{}{
          "html":     "<h1>Invoice #1234</h1><p>Total: $15,000</p>",
          "pageSize": "letter",
          "margins":  map[string]int{"top": 50, "right": 50, "bottom": 50, "left": 50},
      },
  }
  ```

  ```ruby Ruby theme={null}
  response = http.post(uri, {
    template: 'pdf',
    title: 'Invoice #1234',
    content: {
      html: '<h1>Invoice #1234</h1><p>Total: $15,000</p>',
      pageSize: 'letter'
    }
  }.to_json)
  ```

  ```rust Rust theme={null}
  let response = client.post("https://genui.sh/api/artifacts")
      .header("Authorization", format!("Bearer {}", api_key))
      .json(&json!({
          "template": "pdf",
          "title": "Invoice #1234",
          "content": {
              "html": "<h1>Invoice #1234</h1><p>Total: $15,000</p>",
              "pageSize": "letter"
          }
      }))
      .send().await?;
  ```

  ```csharp .NET theme={null}
  var response = await client.PostAsJsonAsync("https://genui.sh/api/artifacts", new {
      template = "pdf",
      title = "Invoice #1234",
      content = new {
          html = "<h1>Invoice #1234</h1><p>Total: $15,000</p>",
          pageSize = "letter"
      }
  });
  ```
</CodeGroup>

## Example: Markdown to PDF

```json theme={null}
{
  "template": "pdf",
  "title": "Project Proposal",
  "content": {
    "markdown": "# Project Proposal\n\n## Overview\n\nThis document outlines our proposed solution.\n\n## Timeline\n\n| Phase | Duration |\n|-------|----------|\n| Discovery | 2 weeks |\n| Development | 8 weeks |\n| Testing | 2 weeks |\n\n## Budget\n\n**Total: $50,000**",
    "pageSize": "a4",
    "orientation": "portrait"
  }
}
```

## Response with Download URL

```json theme={null}
{
  "id": "art_pdf_abc123",
  "template": "pdf",
  "title": "Invoice #1234",
  "status": "active",
  "downloadUrl": "https://genui.sh/api/artifacts/art_pdf_abc123/download",
  "createdAt": "2024-01-15T12:00:00Z"
}
```

## Page Sizes

| Size     | Dimensions   |
| -------- | ------------ |
| `a4`     | 210 x 297 mm |
| `letter` | 8.5 x 11 in  |
| `legal`  | 8.5 x 14 in  |

## Use Cases

* **Invoices**: Billing documents
* **Contracts**: Agreements and legal documents
* **Reports**: Formal reports and summaries
* **Certificates**: Awards and certifications
* **Exports**: Printable versions of any content
