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

# POST /generate/pdf

> Generate a pattern and return it as a downloadable PDF.

# Generate Pattern PDF

```
POST /api/v1/generate/pdf
```

Same as `/generate` but returns a binary PDF file instead of JSON. The PDF includes a materials list and complete assembly guide.

If your API key has a `custom_logo_url` configured, it will be used in the PDF header instead of the PixCraft logo.

## Request body

Same parameters as [POST /generate](/api-reference/generate).

## Example request

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://www.pixcraft.es/api/v1/generate/pdf \
    -H "Authorization: Bearer px_live_your_key" \
    -H "Content-Type: application/json" \
    -d '{
      "image_url": "https://example.com/sunset.jpg",
      "niche": "curtains",
      "width_cm": 200,
      "height_cm": 250,
      "max_colors": 8
    }' \
    --output pattern.pdf
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://www.pixcraft.es/api/v1/generate/pdf', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer px_live_your_key',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      image_url: 'https://example.com/sunset.jpg',
      niche: 'curtains',
      width_cm: 200,
      height_cm: 250,
      max_colors: 8,
    }),
  });

  const buffer = await response.arrayBuffer();
  const fs = require('fs');
  fs.writeFileSync('pattern.pdf', Buffer.from(buffer));
  ```

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

  response = requests.post(
      'https://www.pixcraft.es/api/v1/generate/pdf',
      headers={'Authorization': 'Bearer px_live_your_key'},
      json={
          'image_url': 'https://example.com/sunset.jpg',
          'niche': 'curtains',
          'width_cm': 200,
          'height_cm': 250,
          'max_colors': 8,
      }
  )

  with open('pattern.pdf', 'wb') as f:
      f.write(response.content)
  ```

  ```php PHP theme={null}
  $response = $client->post('https://www.pixcraft.es/api/v1/generate/pdf', [
      'headers' => ['Authorization' => 'Bearer px_live_your_key'],
      'json' => [
          'image_url' => 'https://example.com/sunset.jpg',
          'niche' => 'curtains',
          'width_cm' => 200,
          'height_cm' => 250,
          'max_colors' => 8,
      ],
  ]);

  file_put_contents('pattern.pdf', $response->getBody());
  ```
</CodeGroup>

## Response

The response is a binary PDF file:

* **Content-Type:** `application/pdf`
* **Content-Disposition:** `attachment; filename="pixcraft-curtains-133x125.pdf"`

The PDF contains:

1. **Configuration summary** — dimensions, grid size, unit size
2. **Materials list** — color swatches with names, quantities, and percentages
3. **Assembly guide** — step-by-step instructions with color runs (direction adapts per niche)
4. **Color summary** — positions grouped by color (crossstitch and embroidery only)

## Custom logos (Business & Enterprise)

If your API key has a `custom_logo_url` set, the PDF header will use your brand name instead of "PixCraft". Configure this in your [API Keys dashboard](https://pixcraft.es/dashboard/api).

## Common errors

Same as [POST /generate](/api-reference/generate).
