Writes the document out: to a download, a Blob, an ArrayBuffer, a base64 string, or an upload. Every method needs the export feature.
Obtain the exporter from viewer.createExporter(). It carries what the viewer holds — the form values and signatures the user entered — and, before it reads anything, writes in what the screen holds and the document does not yet: Edit Text's pending edits (the tool stays active), an annotation selected on the page, the entry being typed into a formatted field. When pending edits cannot be written the export rejects with INVALID_STATE instead of going out without them; when the document was reloaded under it (an undo, a commit, a page operation) it rejects with INVALID_STATE too — export again. It reports exportStarted / exportCompleted on the viewer, and an export of the whole document clears hasUnsavedChanges. new PDFExporter(document, config?) is the document as loaded, with none of that: for a headless export, or when you genuinely want the untouched file; it reports to no viewer.
download, getBlob, getArrayBuffer and getBase64 accept options?: ExportOptions — { flatten?, invalidateSignatures?, pages?, onProgress?, signal? }; uploadTo takes UploadOptions: the same options, and the request's method and headers. A flatten left out comes from ExportConfig. A page subset is a new document and never carries a signature. Flattening/saving shows a determinate, cancelable card once the work has run 300 ms; onProgress(done, total) and signal serve a progress indicator of your own.
Each method rejects with FEATURE_NOT_LICENSED when the license lacks export, INVALID_ARGUMENT when pages is empty or names a page the document does not have, INVALID_STATE when flatten is asked of a signed document without invalidateSignatures, PAGE_ERROR when a page cannot be loaded for flattening, EXPORT_FAILED when the document cannot be written, ABORTED when signal aborts, and DOCUMENT_CLOSED after doc.close().
classviewer.createExporter(config?) (recommended) | new PDFExporter(document, config?)
Usage
TypeScript
const exporter = viewer.createExporter();
const { sizeBytes } = await exporter.download('report.pdf', { flatten: true });
// Only if you want the document as loaded, ignoring unsaved user input:const raw = newPDFExporter(doc, { flatten: false });
const blob = await raw.getBlob();
Exports the document as loaded: without the form values and signatures a viewer holds, without pending Edit Text edits, and reporting to no viewer. For the document as the user sees it, use viewer.createExporter(config?), whose defaults are the viewer's export option.
Parameter
Type
Description
document
PDFDocument
An open PDFDocument.
config?
ExportConfig
The export defaults — the same ExportConfig a viewer takes.
ReturnsPromise<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.
FEATURE_NOT_LICENSED when the license lacks export.
INVALID_ARGUMENT when pages is empty or names a page the document does not have.
INVALID_STATE when flatten is asked of a signed document without invalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.
PAGE_ERROR when a page cannot be loaded for flattening.
EXPORT_FAILED when the document cannot be written.
FEATURE_NOT_LICENSED when the license lacks export.
INVALID_ARGUMENT when pages is empty or names a page the document does not have.
INVALID_STATE when flatten is asked of a signed document without invalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.
PAGE_ERROR when a page cannot be loaded for flattening.
EXPORT_FAILED when the document cannot be written.
FEATURE_NOT_LICENSED when the license lacks export.
INVALID_ARGUMENT when pages is empty or names a page the document does not have.
INVALID_STATE when flatten is asked of a signed document without invalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.
PAGE_ERROR when a page cannot be loaded for flattening.
EXPORT_FAILED when the document cannot be written.
FEATURE_NOT_LICENSED when the license lacks export.
INVALID_ARGUMENT when pages is empty or names a page the document does not have.
INVALID_STATE when flatten is asked of a signed document without invalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.
PAGE_ERROR when a page cannot be loaded for flattening.
EXPORT_FAILED when the document cannot be written.
Upload the exported PDF (e.g. to an S3 presigned URL). Sends Content-Type: application/pdf unless headers overrides it. Needs export.
Parameter
Type
Description
url
string
Where to send the file, e.g. an S3 presigned URL.
options?
UploadOptions
Every ExportOptions field, and the request's method (default 'PUT'), headers (Content-Type: application/pdf is sent unless these name one, in any case) and credentials (fetch's; same-origin by default, include for a cookie-authenticated endpoint on another origin). The signal cancels the upload too.
ReturnsPromise<Response> The fetchResponse. Does not reject on an HTTP error status — check response.ok.
NETWORK_ERROR when the request could not be sent at all (the address, the network, or a CORS refusal: the response must allow your origin).
ABORTED when signal aborts, during the export or the upload.
FEATURE_NOT_LICENSED when the license lacks export.
INVALID_ARGUMENT when pages is empty or names a page the document does not have, or when headers holds a name or value a request cannot carry.
INVALID_STATE when flatten is asked of a signed document without invalidateSignatures; from a viewer's exporter, when pending edits cannot be written or the document was reloaded under it.
PAGE_ERROR when a page cannot be loaded for flattening.
EXPORT_FAILED when the document cannot be written.