Univer PDFs API
Create, find, save, enter, and unload PDF units through the PDF Facade API.
The PDF Facade adds PDF units and page entry points to FUniver. Import its side-effect entry before creating the API object.
Enable the PDF Facade
import { FUniver } from '@univerjs/core/facade'import '@univerjs-pro/pdfs/facade'const univerAPI = FUniver.newAPI(univer)Register UniverPdfsPlugin in the Univer instance so the application can host PDF units.
Create, find, and save PDF units
When document is omitted, createPdf() creates a unit with one blank A4 page. Pass a snapshot previously returned by save() to restore a unit.
const pdf = univerAPI.createPdf({ id: 'project-brief', name: 'Project brief',})const activePdf = univerAPI.getActivePdf()const samePdf = univerAPI.getPdf(pdf.getId())const snapshot = pdf.save()Use Facade methods or commands to update a running PDF. Treat the saved snapshot as detached persistence data.
Enter a page
FPdfPage is the common entry point for the page's editable overlays and imported native text:
const firstPage = pdf.getPageByIndex(0) ?? pdf.insertPage()const elements = firstPage.getElements()const nativeText = firstPage.getTextSpans()Continue with Pages and Elements, Text and Lists, Tables, Images and Dividers, or Annotations and Native Text for focused operations.
Unload a PDF unit
Unload one PDF unit by ID when it is no longer needed. Dispose the root univer instance only when the whole application is being destroyed.
const pdf = univerAPI.getActivePdf()if (pdf) { univerAPI.disposeUnit(pdf.getId())}For exact signatures and return types, see the PDF Facade reference.
How is this guide?