FPdf
Facade for a PDF unit.
Access
Access through:
Setup
Register @univerjs-pro/pdfs or a preset that includes it. In plugin mode, import @univerjs-pro/pdfs/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs-pro/pdfs
FPdf.getDocument
Return the current source PDF document.
getDocument(): IPdfDocumentReturns
The current source document.
Examples
const pdf = univerAPI.getActivePdf()console.log(pdf?.getDocument().pages.length)Types: IPdfDocument
Package: @univerjs-pro/pdfs · Type definitions
FPdf.getId
Return the PDF unit ID.
getId(): stringReturns
The stable PDF unit ID.
Examples
const pdf = univerAPI.getActivePdf()console.log(pdf?.getId())Package: @univerjs-pro/pdfs · Type definitions
FPdf.getModel
Return the underlying PDF document model.
getModel(): PdfDocumentModelReturns
The underlying model.
Examples
const pdf = univerAPI.getActivePdf()console.log(pdf?.getModel().getUnitId())Types: PdfDocumentModel
Package: @univerjs-pro/pdfs · Type definitions
FPdf.getName
Return the PDF unit name.
getName(): stringReturns
The current PDF unit name.
Examples
const pdf = univerAPI.getActivePdf()console.log(pdf?.getName())Package: @univerjs-pro/pdfs · Type definitions
FPdf.getPageById
Return a PDF page by ID.
getPageById(id: string): FPdfPage | nullParameters
id— Required. The page ID.
Returns
The page Facade, or null when it does not exist.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf?.getPageById('page-id')console.log(page)Types: FPdfPage
Package: @univerjs-pro/pdfs · Type definitions
FPdf.getPageByIndex
Return a PDF page by zero-based index.
getPageByIndex(index: number): FPdfPage | nullParameters
index— Required. The zero-based page index.
Returns
The page Facade, or null when the index is out of range.
Examples
const pdf = univerAPI.getActivePdf()const firstPage = pdf?.getPageByIndex(0)console.log(firstPage)Types: FPdfPage
Package: @univerjs-pro/pdfs · Type definitions
FPdf.getPages
Return all current PDF pages in materialized document order.
getPages(): FPdfPage[]Returns
The current page Facades.
Examples
const pdf = univerAPI.getActivePdf()console.log(pdf?.getPages())Types: FPdfPage
Package: @univerjs-pro/pdfs · Type definitions
FPdf.insertPage
Insert a blank PDF page at a zero-based index, or append it when no index is provided.
The new page inherits the adjacent page's size, rotation, and PDF boxes. An A4 page is created when the document has no existing pages.
insertPage(index?: number): FPdfPageParameters
index— Optional. The zero-based insert index. Omit it to append the page.
Returns
The created page Facade.
Throws
If the index is outside the document page boundaries.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf?.insertPage()console.log(page?.getIndex())Types: FPdfPage
Package: @univerjs-pro/pdfs · Type definitions
FPdf.save
Save and return a detached PDF unit snapshot.
save(): IPdfUnitDataReturns
The complete current PDF unit snapshot.
Examples
const pdf = univerAPI.getActivePdf()const snapshot = pdf?.save()console.log(snapshot)Types: IPdfUnitData
Package: @univerjs-pro/pdfs · Type definitions
How is this guide?