Import and export
The APIs below require a conversion backend. Begin with file exchange integration to connect file uploads, conversion, task queries, and downloads, then configure the browser plugins. Snapshot APIs use the same backend but do not require a collaborative document. The collaboration Exchange example demonstrates Sheets, so confirm that the target release supports the required file types.
If an export fails, see license error codes and task failure handling.
Supported formats
The table covers the browser APIs on this page. Office file conversion also requires a backend that supports the same document type and format.
| Import | Export |
|---|---|
.pdf | .pdf |
These APIs import and export PDF files only. 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
Pass a browser File or a URL, then 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 the conversion task does not persist:
const snapshot = await univerAPI.importPdfToSnapshotAsync(file)if (snapshot) { univerAPI.createPdf(snapshot)}Export and download
Export a persisted Unit by its 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. Printing in the browser is a separate workflow that opens the system print dialog. See Print.
Append pages and export an open PDF
The exchange facade also works on a PDF that is already open. univerAPI.appendPdfAsync(file, unitId?) imports the file and appends its pages to the given PDF, or to the active PDF when the unit ID is omitted. It resolves to false when there is no target or the pages cannot be appended.
univerAPI.exportPdfAsync(unitId?) commits text that is still being edited on the canvas and exports the open document, so it works for a local snapshot PDF as well as for a persisted unit. It resolves to undefined when the pending edit cannot be committed or the document is no longer open.
// Append every page of another PDF to the open document.const appended = await univerAPI.appendPdfAsync(file)// Export the open PDF, including canvas edits that have not been committed yet.const exported = await univerAPI.exportPdfAsync()if (exported) { univerAPI.downloadFile(exported, 'project-brief', 'pdf')}Both methods are added to FUniver by @univerjs-pro/pdfs-exchange-client/facade. Call pdf.appendPdf(snapshot) directly to append an IPdfUnitData you already hold. See PDF Facade API.
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 an application needs to keep the existing import/export menus and UI interactions, the migration example for built-in import/export menus and UI interactions shows how to restore them with a custom plugin. The example includes the full source, which can be viewed online or downloaded.
How is this guide?