# Export

What the toolbar's Download button does: the default file name, whether fields and comments are flattened into the page, whether the button asks first, and whether a "Saved" confirmation follows. Download, `doc.save()` and every `PDFExporter` method need a license that includes `export`.

- Interface: `ExportConfig`
- Config path: `config.export`

## Example

```ts
new PDFViewer(container, doc, {
  export: {
    defaultFilename: 'contract.pdf',
    flatten: true, // every Download locks answers and comments into the page
  },
});
```

## Options (4)

### `defaultFilename`

- Type: `string`
- Default: `'document.pdf'`
- Page: https://kernstra.com/docs/web-sdk/config/export/defaultfilename

Default filename for download. The Download dialog starts from it; with `askOnDownload: false` the file is saved under it straight away.

### `flatten`

- Type: `boolean`
- Default: `false`
- Page: https://kernstra.com/docs/web-sdk/config/export/flatten

Flatten on export: every page's fields and comments, as the page prints (anything not marked to print — a form field included — is dropped); the form itself is removed. By default a download keeps comments and form fields as they are: anyone can still select, edit, reply to or remove them in Acrobat or any other reader, as with Acrobat's own downloads. To hand out locked documents — signed forms, final contracts — turn flattening on for every download, or per call with [`exporter.download(name, { flatten: true })`](https://kernstra.com/docs/web-sdk/api/pdfexporter/download). In the Download dialog this is the one setting that cannot be undone — **Lock in form answers and annotations** — starting from `flatten`, and grayed out on a signed document with the reason, since the signature would not survive.

```ts
export: { flatten: true } // every Download locks answers and comments into the page
```

### `askOnDownload`

- Type: `boolean`
- Default: `true`
- Page: https://kernstra.com/docs/web-sdk/config/export/askondownload

Toolbar Download asks first: file name, pages (all, current, or a range such as `1-3, 5`), and the flatten decision, with the approximate size under it. `false` saves straight away with `defaultFilename` / `flatten` (never locking in a signed document). The progress card and the "Saved" confirmation still show. The Print button's question is [`print.ask`](https://kernstra.com/docs/web-sdk/config/print/ask).

```ts
export: { askOnDownload: false }
```

### `successToast`

- Type: `boolean`
- Default: `true`
- Page: https://kernstra.com/docs/web-sdk/config/export/successtoast

"Saved · 3 pages, 1.2 MB" after Download. `false` drops the confirmation (screen readers are still told). The confirmation says when a PDF/A claim was dropped.

```ts
export: { successToast: false }
```

## Notes

**Three ways to shape the toolbar's Download and Print buttons.** Hide them — [`toolbar.download: false`](https://kernstra.com/docs/web-sdk/config/toolbar/download), [`toolbar.print: false`](https://kernstra.com/docs/web-sdk/config/toolbar/print); with Print hidden, Ctrl / ⌘ + P is left to the browser. Take them over — [`callbacks.onDownload`](https://kernstra.com/docs/web-sdk/config/callbacks/ondownload) / [`callbacks.onPrint`](https://kernstra.com/docs/web-sdk/config/callbacks/onprint): when set, the SDK's dialog and flow do not run; your function does (get the bytes from [`viewer.createExporter()`](https://kernstra.com/docs/web-sdk/api/pdfviewer/createexporter), print with [`viewer.print({ pages })`](https://kernstra.com/docs/web-sdk/api/pdfviewer/print)); Ctrl / ⌘ + P goes to `onPrint` too. Skip the question — `export.askOnDownload: false` saves straight away; [`print.ask: false`](https://kernstra.com/docs/web-sdk/config/print/ask) prints every page.

**Print** asks for a page range and whether annotations print, above a thumbnail of the first page; both Download and Print show a determinate, cancelable progress card while they work.

**Per-call export options** (`exporter.download(name?, options)`, `getBlob`, `getArrayBuffer`, `getBase64`) take `flatten`, `invalidateSignatures` (a flattening export of a signed document is refused with `INVALID_STATE` without it), `pages` (zero-based, in that order), `onProgress(done, total)` and `signal` (an `AbortSignal`; aborting rejects with `ABORTED`); `download()` resolves `{ sizeBytes, pdfA? }` (a `DownloadResult`). `viewer.print({ pages?, annotations? })` prints without asking. See [PDFExporter](https://kernstra.com/docs/web-sdk/api/pdfexporter).

**A page range is a new document**, and a new document has no form: the pages in it that carry form fields are flattened even with `flatten` off, so the answers stay on the page instead of in fields no reader would fill. Its other pages keep their comments editable. Download the whole document to keep a form fillable. A page range of a signed document is unsigned by construction, a new file the signature never covered, so it is not refused.

**PDF/A files.** A PDF/A file (the archival profile of PDF) says so in its XMP metadata; [`doc.pdfA`](https://kernstra.com/docs/web-sdk/api/pdfdocument/pdfa) reads that claim — `{ part: 2, conformance: 'B' }` — or is `null`. The SDK does not check what it writes against PDF/A, so a saved file keeps the claim only when nothing changed it. **Unchanged** — no edit, no filled field, no flatten, no watermark — a download, export or `doc.save()` returns the bytes the file was opened from, claim and all, not re-saved or re-dated. **Changed** — the file is saved without the claim, a plain PDF, and the modification date in its XMP metadata matches the file's new modification date. A page range is a new document and never carries it.

**PDF/A reporting.** `download()` and the [`exportCompleted`](https://kernstra.com/docs/web-sdk/api/events#ev-exportcompleted) event report `pdfA: 'kept' | 'dropped'` for a document that claims PDF/A, and nothing for one that does not. The Download dialog says the file is PDF/A, and the confirmation says when the claim was dropped. A changed file is never saved with the claim: when the claim cannot be edited out of the metadata, the metadata packet is removed, and when that cannot be done either the export (and `doc.save()`) fails with `EXPORT_FAILED` rather than hand out a file that claims PDF/A. To deliver a changed file as PDF/A, convert the download with a PDF/A tool.

**PDF/A limits.** A claim stored in compressed metadata is not read (PDF/A producers write it plain), a metadata packet over 1 MiB is not read either (such a file is treated as making no claim, so a changed copy keeps its packet as it was), and an encrypted file — which PDF/A does not allow — goes out as a changed file whose claim is dropped (`'dropped'`), its metadata packet removed when the claim cannot be edited.


Web page: https://kernstra.com/docs/web-sdk/config/export
