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.
For export failures, see license error codes and task failure handling.
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.
Removal of built-in import/export menus and UI interactions
Note
Starting with version 1.2.0, Univer no longer includes built-in import/export menus and UI interactions. The underlying services and Facade APIs remain available.
If your application needs to retain the existing import/export menus and UI interactions, see the migration example for built-in import/export menus and UI interactions to migrate using a custom plugin. The example provides complete source code for online viewing and download.
How is this guide?