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

# Generate Multiple PDFs (Batch)

> Generate multiple PDFs from different templates in a single API call with detailed result tracking

## Overview

The Generate PDFs Batch endpoint allows you to create multiple PDF documents from different templates in a single API call. This is perfect for scenarios where you need to generate many documents at once, such as bulk invoice processing, mass certificate generation, or report batching.

<Info>
  Each PDF in the batch is processed individually with detailed success/failure tracking. Partial success is supported - some PDFs can succeed while others fail.
</Info>

## Key Features

<CardGroup cols={2}>
  <Card title="Bulk Processing" icon="layer-group">
    **Multiple Templates**

    Generate PDFs from different templates in a single request, each with unique data and filenames.
  </Card>

  <Card title="Detailed Results" icon="list-check">
    **Individual Tracking**

    Get detailed success/failure status for each PDF with specific error messages and download URLs.
  </Card>

  <Card title="Partial Success" icon="shield-check">
    **Resilient Processing**

    If some PDFs fail, successful ones are still generated and available for download.
  </Card>

  <Card title="Efficiency" icon="bolt">
    **Optimized Performance**

    Process multiple PDFs in a single request.
  </Card>
</CardGroup>

## Request Structure

The request body is a direct array of PDF generation requests. Each item has the same structure as the single PDF endpoint.

### Basic Batch Request

<CodeGroup>
  ```json Simple Batch theme={null}
  [
    {
      "templateId": "invoice_template_123",
      "data": {
        "customerName": "John Smith",
        "invoiceNumber": "INV-001",
        "amount": 1299.99
      },
      "filename": "invoice-001.pdf"
    },
    {
      "templateId": "receipt_template_456", 
      "data": {
        "customerName": "Jane Doe",
        "receiptNumber": "REC-001",
        "total": 45.99
      },
      "filename": "receipt-001.pdf"
    }
  ]
  ```
</CodeGroup>

### Mixed Template Batch

<CodeGroup>
  ```json Different Templates theme={null}
  [
    {
      "templateId": "certificate_template",
      "data": {
        "studentName": "Alice Johnson",
        "courseName": "Advanced JavaScript",
        "completionDate": "2024-01-15",
        "grade": "A+"
      },
      "filename": "certificate-alice-javascript.pdf"
    },
    {
      "templateId": "invoice_template",
      "data": {
        "company": "Acme Corp",
        "invoiceNumber": "INV-2024-001",
        "items": [
          {
            "name": "Consulting",
            "amount": 5000.00
          }
        ]
      },
      "filename": "invoice-acme-001.pdf"
    },
    {
      "templateId": "report_template",
      "data": {
        "reportTitle": "Q1 Sales Report",
        "quarter": "Q1 2024",
        "totalSales": 125000
      },
      "filename": "q1-sales-report.pdf"
    }
  ]
  ```
</CodeGroup>

## Response Structure

The response includes detailed results for each PDF generation attempt, plus summary statistics.

### Successful Batch Response

<CodeGroup>
  ```json Full Success theme={null}
  {
    "success": true,
    "message": "Batch PDF generation completed: 2 successful, 0 failed",
    "results": [
      {
        "index": 0,
        "success": true,
        "data": {
          "filePath": "user_123/invoice-001.pdf",
          "downloadUrl": "https://storage.example.com/invoice-001.pdf?token=xyz",
          "expiresAt": "2024-01-15T23:59:59.000Z",
          "filename": "invoice-001.pdf",
          "size": 45678
        }
      },
      {
        "index": 1,
        "success": true,
        "data": {
          "filePath": "user_123/receipt-001.pdf", 
          "downloadUrl": "https://storage.example.com/receipt-001.pdf?token=abc",
          "expiresAt": "2024-01-15T23:59:59.000Z",
          "filename": "receipt-001.pdf",
          "size": 23456
        }
      }
    ],
    "summary": {
      "total": 2,
      "successful": 2,
      "failed": 0
    }
  }
  ```
</CodeGroup>

### Partial Success Response

<CodeGroup>
  ```json Partial Success theme={null}
  {
    "success": true,
    "message": "Batch PDF generation completed: 1 successful, 1 failed",
    "results": [
      {
        "index": 0,
        "success": true,
        "data": {
          "filePath": "user_123/invoice-001.pdf",
          "downloadUrl": "https://storage.example.com/invoice-001.pdf?token=xyz",
          "expiresAt": "2024-01-15T23:59:59.000Z",
          "filename": "invoice-001.pdf",
          "size": 45678
        }
      },
      {
        "index": 1,
        "success": false,
        "error": {
          "code": "TEMPLATE_NOT_FOUND",
          "message": "Template not found"
        }
      }
    ],
    "summary": {
      "total": 2,
      "successful": 1,
      "failed": 1
    }
  }
  ```
</CodeGroup>


## OpenAPI

````yaml post /api/generate-pdfs-batch
openapi: 3.1.0
info:
  title: Docurate PDF API
  description: Generate PDFs from JSON templates with data binding
  version: 1.0.0
servers:
  - url: https://api.curatepdf.com
    description: Production
security:
  - apiKeyAuth: []
paths:
  /api/generate-pdfs-batch:
    post:
      tags:
        - PDF
      summary: Generate Multiple PDFs (Batch)
      description: Generate multiple PDFs from different templates in a single API call
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                type: object
                properties:
                  templateId:
                    type: string
                    example: template_123
                  data:
                    type: object
                    example:
                      name: John Doe
                      company: Acme Corp
                  filename:
                    type: string
                    example: document1.pdf
                required:
                  - templateId
              example:
                - templateId: template_123
                  data:
                    name: John Doe
                    company: Acme Corp
                  filename: document1.pdf
                - templateId: template_456
                  data:
                    name: Jane Smith
                    department: Marketing
                  filename: document2.pdf
              minItems: 1
      responses:
        '200':
          description: Batch PDF generation completed
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                    description: Overall success if at least one PDF was generated
                  message:
                    type: string
                    example: 'Batch PDF generation completed: 2 successful, 0 failed'
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                          example: 0
                          description: Index of the request in the original array
                        success:
                          type: boolean
                          example: true
                        data:
                          type: object
                          properties:
                            filePath:
                              type: string
                              example: user_123/document1.pdf
                            downloadUrl:
                              type: string
                              example: https://storage.example.com/document1.pdf
                            expiresAt:
                              type: string
                              example: '2024-01-15T23:59:59.000Z'
                            filename:
                              type: string
                              example: document1.pdf
                            size:
                              type: integer
                              example: 123456
                          description: Present when success is true
                        error:
                          type: object
                          properties:
                            code:
                              type: string
                              example: TEMPLATE_NOT_FOUND
                            message:
                              type: string
                              example: Template not found
                          description: Present when success is false
                  summary:
                    type: object
                    properties:
                      total:
                        type: integer
                        example: 2
                        description: Total number of requests
                      successful:
                        type: integer
                        example: 2
                        description: Number of successful PDF generations
                      failed:
                        type: integer
                        example: 0
                        description: Number of failed PDF generations
        '400':
          description: Bad request - Invalid array or empty array
        '401':
          description: Authentication failed
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
      security:
        - apiKeyAuth: []
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key for accessing the Docurate PDF API

````