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

# Generate Document

> Generates a PDF document from a published document template.

This endpoint is for generating a document based on a template you've published to a team. To publish a document, see the [publish command](a/cli#htmldocs-publish-file).

You can find the ids of your published documents in the [dashboard](https://htmldocs.com/dashboard).


## OpenAPI

````yaml POST /api/documents/{documentId}
openapi: 3.0.1
info:
  title: htmldocs API
  description: API for generating PDF documents from JSX templates
  version: 1.0.0
servers:
  - url: https://htmldocs.com
security:
  - bearerAuth: []
paths:
  /api/documents/{documentId}:
    post:
      description: Generates a PDF document from a published document template.
      parameters:
        - name: documentId
          in: path
          description: UUID or custom ID of the document template
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - props
              properties:
                props:
                  type: object
                  description: Props to pass to the document component
                  additionalProperties: true
                format:
                  type: string
                  enum:
                    - pdf
                    - base64
                    - json
                  description: >-
                    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`
                  default: pdf
                size:
                  $ref: '#/components/schemas/DocumentSize'
                orientation:
                  $ref: '#/components/schemas/Orientation'
      responses:
        '200':
          description: Generated document in requested format
          content:
            application/pdf:
              schema:
                type: string
                description: Binary PDF file (when format=pdf)
                format: binary
            application/json:
              schema:
                oneOf:
                  - type: object
                    description: Base64 encoded PDF (when format=base64)
                    properties:
                      data:
                        type: string
                        format: base64
                  - type: object
                    description: PDF URL (when format=json)
                    properties:
                      url:
                        type: string
                        format: uri
        '404':
          description: Document template not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Generation limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    DocumentSize:
      type: string
      description: Page size (A3, A4, A5, letter, legal, or custom size like '8.5in 11in')
    Orientation:
      type: string
      enum:
        - portrait
        - landscape
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Error message describing what went wrong
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API-Key
      description: 'API key for authentication. Use format: Bearer <api-key>'

````