PDFExporter.download()
Download PDF as a file. A download confirms itself in one line ("Saved · 6 pages, 1.2 MB"); export.successToast
: false drops the line. Needs export.methodExportsince 1.0.0
Signature
download(filename?: string, options?: ExportOptions): Promise<DownloadResult>
Parameters
| Parameter | Type | Description |
|---|---|---|
| filename? | string | The file name; export.defaultFilename when omitted. |
| options? | ExportOptions | { flatten?, invalidateSignatures?, pages?, onProgress?, signal? }. |
Returns
Promise<DownloadResult> { sizeBytes, pdfA? } — the file's size in bytes and, for a document that claims PDF/A, whether the file saved still claims it: 'kept' for a document nobody changed, 'dropped' for a changed one, or a page range.
Throws
FEATURE_NOT_LICENSEDwhen the license lacksexport.INVALID_ARGUMENTwhenpagesis empty or names a page the document does not have.INVALID_STATEwhenflattenis asked of a signed document withoutinvalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.PAGE_ERRORwhen a page cannot be loaded for flattening.EXPORT_FAILEDwhen the document cannot be written.ABORTEDwhensignalaborts.DOCUMENT_CLOSEDafterdoc.close().
Example
TypeScript
const result = await viewer.createExporter().download('signed.pdf', { flatten: true, onProgress: (done, total) => setProgress(done / total), }); console.log(result.sizeBytes);