# PDF Exports

:::warning

Preview. `GET /v1-preview/jobs/{id}/pdf` may change without a new versioned route until it is announced as stable. See [Versioning and Preview](/versioning-and-preview).

:::

Once a job has finished you can get its certificates back as PDFs, regrouped the way you file them: per certificate, per supplier, or per heat. The files are generated from the job's own pages the first time you ask and kept for later calls. Exports are **not billed**.

```bash
curl "https://<gateway-host>/v1-preview/jobs/<jobId>/pdf?groupBy=heat" \
  -H "Authorization: Bearer $GOSMARTER_API_KEY"
```

To fetch the PDFs the moment a job finishes, register a [webhook](/webhooks) and call this route from your handler for `job.completed`.

## Choosing a grouping

| `groupBy` | You get |
|---|---|
| `certificate` | Each certificate's own PDF (for a pack, one per supplier section), named `{supplier}-{nn}.pdf`. |
| `supplier` | The certificates of one supplier merged into one PDF, named `{supplier}.pdf`. |
| `heat` | One PDF per heat, named `{heat}-{supplier}.pdf`, built from the pages the extraction found that heat's data on, merged across the job's certificates. |

Add `heat=<heat code>` together with `groupBy=heat` to get only that heat's files. A heat that is not in the result returns 404. A heat that is in the result but has no page numbers (the extraction found it but not where) returns 422 with `pdf_export_heat_has_no_pages`; without `heat`, such a heat is skipped and its pages stay in the unassigned file.

## Heats, suppliers and pages

- A heat is identified by the pair (heat code, supplier), because two suppliers can issue the same heat number. Both get their own file.
- A page that carries several heats' data is included in each of those heats' PDFs.
- Pages that belong to no heat are never dropped: they go to `unassigned-{supplier}.pdf`, one per certificate. A certificate with no heats at all is exported whole as unassigned.
- File names contain only letters, digits, `.`, `-` and `_`. Names that would collide get a numeric suffix (`-2`, `-3`).
- Only certificates that completed are included. A failed certificate has no export.
- No watermark or stamp is added.

## Response

The response is JSON with signed links, not PDF bytes, so the files never pass through the gateway.

```json
{
  "jobId": "5b0a6f0e-8d37-4b3a-9c43-2d4a7c1f9a10",
  "groupBy": "heat",
  "expiresAt": "2026-12-02T15:00:00Z",
  "archive": { "name": "archive.zip", "url": "https://..." },
  "files": [
    {
      "name": "H1-Celsa.pdf",
      "url": "https://...",
      "pageCount": 3,
      "heat": "H1",
      "supplier": "Celsa",
      "unassigned": false,
      "certificateIds": ["..."]
    }
  ]
}
```

- Each `url` is read-only and stops working at `expiresAt` (one hour). Call the endpoint again for fresh links; the files are not regenerated.
- `archive` is a ZIP of every file. It is left out when you pass `heat` or when there is only one file.
- Deleting the job removes its exports.

## Limits

One export is bounded, because a page shared by several heats is copied into each of them:

| Limit | Value | When exceeded |
|---|---|---|
| Heats listed by one certificate | 200 | 422, `pdf_export_heat_limit` |
| Output pages in one export (a shared page counts in each heat) | 2000 | 422, `pdf_export_page_limit` |
| Output size of one export | 200 MiB | 413, `pdf_export_size_limit` |

The message names the limit that was hit. An export is never truncated: use `heat=` for one heat, or `groupBy=certificate`.

The source PDFs are stored for 7 days. After that a first export returns 410 (`pdf_export_source_expired`); the JSON result is still available. Exports already built stay available until the job is deleted.

## Errors

| Status | Meaning |
|---|---|
| 400 | `groupBy` is missing or not one of `certificate`, `supplier`, `heat`, or `heat` was used without `groupBy=heat`. |
| 404 | No such job for this account, or the heat is not in the result. |
| 409 | The job has not finished, or has no completed certificate. |
| 410 | The source PDFs have expired (7 days). |
| 413 | The export would exceed the size limit. |
| 422 | The export would exceed the heat or page limit, or `heat` has no page numbers (`pdf_export_heat_has_no_pages`). |
| 503 | Too many exports are being prepared; retry after a few seconds. |

See [Errors and Status Codes](/errors) for the rest.
