Import and export
The APIs below need a conversion backend. Follow file exchange integration to connect uploads, conversion, task queries, and downloads, then configure the browser plugins. Snapshot APIs also need that backend, but do not require a collaborative document. The collaboration Exchange example demonstrates Sheets; check that your target release supports the file types you need.
Supported formats
The table describes the browser APIs on this page. Office file conversion requires a backend that supports the same document type and format.
| Import | Export |
|---|---|
.pdf | .pdf |
These APIs import and export PDF files. They do not convert PDF content to DOCX, XLSX, or PPTX. Browser printing is a separate workflow.
Choose a data path
| Path | Persists a server unit | Requires collaboration | Conversion server |
|---|---|---|---|
| Unit ID | Yes | Yes | Required |
| Snapshot | No | No | Required |
Import to a persisted unit
The input can be a browser File or a URL. Load the returned unit through the configured collaboration client.
const unitId = await univerAPI.importPdfToUnitIdAsync(file)if (unitId) { const pdf = await univerAPI.getCollaboration().loadPdfAsync(unitId) console.log(pdf?.getName())}Import to a snapshot
Use snapshot import for a local PDF unit that should not be persisted as part of the conversion task:
const snapshot = await univerAPI.importPdfToSnapshotAsync(file)if (snapshot) { univerAPI.createPdf(snapshot)}Export and download
Export a persisted unit by ID:
const file = await univerAPI.exportPdfByUnitIdAsync(unitId)if (file) { univerAPI.downloadFile(file, 'project-brief', 'pdf')}Export the current local snapshot without persisting it first:
const pdf = univerAPI.getActivePdf()if (pdf) { const file = await univerAPI.exportPdfBySnapshotAsync(pdf.save()) if (file) { univerAPI.downloadFile(file, pdf.getName(), 'pdf') }}These APIs return a File. Browser printing is a separate workflow that opens the system print dialog; see Print.
How is this guide?