---
title: "POST /api/generate"
method: POST
path: "/api/generate"
---

# POST /api/generate

`POST /api/generate`

Generates a PDF document from raw HTML content and/or a URL. If both are provided, the HTML content will be injected into the page at the specified URL.

## Request body

- union
  - object
    - `html` string, required — HTML content to convert to PDF or inject into the page at the specified URL
    - `url` string, uri — URL of the webpage to convert to PDF or use as a base for HTML injection
    - `format` 'pdf' | 'base64' | 'json' — Response format. `pdf` returns a binary PDF file, `base64` returns the PDF encoded as base64 in JSON, `json` returns a URL to download the PDF. Defaults to `pdf`
    - `size` string — Page size (A3, A4, A5, letter, legal, or custom size like '8.5in 11in')
    - `orientation` 'portrait' | 'landscape'
  - object
    - `html` string — HTML content to convert to PDF or inject into the page at the specified URL
    - `url` string, uri, required — URL of the webpage to convert to PDF or use as a base for HTML injection
    - `format` 'pdf' | 'base64' | 'json' — Response format. `pdf` returns a binary PDF file, `base64` returns the PDF encoded as base64 in JSON, `json` returns a URL to download the PDF. Defaults to `pdf`
    - `size` string — Page size (A3, A4, A5, letter, legal, or custom size like '8.5in 11in')
    - `orientation` 'portrait' | 'landscape'

## Response `200`

Generated document in requested format

- union
  - object — Base64 encoded PDF (when format=base64)
    - `data` string, base64
  - object — PDF URL (when format=json)
    - `url` string, uri

## Other responses

- `400` — Invalid request body
- `422` — Generation limit exceeded
- `500` — Internal server error

---

[API](https://skmtc.dev/htmldocs-js/apis/htmldocs-api.md) · [All operations](https://skmtc.dev/htmldocs-js/apis/htmldocs-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/htmldocs-js/htmldocs-api/revisions/e3c5bbaba462/schema)
