| Packages | @univerjs-pro/pdfs |
|---|
Facade APIs for creating, reading, and editing Univer PDF units.
Import
@univerjs-pro/pdfs/facadebefore using these APIs in plugin mode.
For setup and task-oriented examples, start with the Univer PDFs guide.
Unit access
TypeScript
createPdf(data?: Partial<IPdfUnitData>, options?: ICreateUnitOptions): FPdfgetActivePdf(): FPdf | nullgetPdf(id: string): FPdf | nullgetPdfTableThemePresets(): ReadonlyArray<Readonly<IPdfTableThemePreset>>FPdf
| Category | Methods |
|---|---|
| Identity and data | getId, getName, save, getDocument, getModel |
| Pages | insertPage, getPages, getPageById, getPageByIndex |
TypeScript
getId(): stringgetName(): stringsave(): IPdfUnitDatagetDocument(): IPdfDocumentgetModel(): PdfDocumentModelinsertPage(index?: number): FPdfPagegetPages(): FPdfPage[]getPageById(id: string): FPdfPage | nullgetPageByIndex(index: number): FPdfPage | nullFPdfPage
FPdfPage resolves existing page elements and inserts editable text boxes, paragraphs, lists, tables, dividers, annotations, and images.
TypeScript
getId(): stringgetIndex(): numbergetData(): Readonly<IPdfPage>getElements(): FPdfPageElement[]getElementById(id: string): FPdfPageElement | nullgetTextBoxes(): FPdfTextBox[]getImages(): FPdfImage[]getParagraphs(): FPdfParagraph[]getLists(): FPdfList[]getTables(): FPdfTable[]getDividers(): FPdfDivider[]getAnnotations(): FPdfAnnotation[]getTextSpans(): FPdfTextSpan[]insertTextBox(options: IPdfTextBoxInsertOptions): FPdfTextBoxinsertParagraph(options: IPdfParagraphInsertOptions): FPdfParagraphinsertList(options: IPdfListInsertOptions): FPdfListinsertTable(options: IPdfTableInsertOptions): FPdfTableinsertDivider(options?: IPdfDividerInsertOptions): FPdfDividerinsertAnnotation(options: IPdfAnnotationInsertOptions): FPdfAnnotationnewImage(existing?: FPdfImage | string): FPdfImageBuilderinsertImage(info: IPdfImageBuilderInfo, index?: number): FPdfImageinsertImageAsync(source: string | IFBlobSource, options?: IPdfImageInsertOptions): Promise<FPdfImage>Page elements
Every FPdfPageElement supports identity, transform, visibility, locking, z-order, and removal. Specialized wrappers add content editing:
| Wrapper | Methods |
|---|---|
FPdfTextBox | getText, getTextRuns, setText, setTextStyle, getTextAnchor, setTextAnchor |
FPdfParagraph | getBlocks, insertBlock, appendBlock, setBlockText, setBlockStyle, removeBlock |
FPdfList | getItems, insertItem, setItemText, removeItem, changeItemLevel, setPreset, setStartNumber |
FPdfTable | getRowCount, getColumnCount, getCell, resize, getTheme, setTheme |
FPdfTableCell | getText, setText, getStyle, setStyle |
FPdfDivider | getStroke, setStroke |
FPdfAnnotation | getAnnotationType, getMarkup, getInk, getStyle, setStyle |
FPdfImage | getSource, getImageSourceType, setSource, getCrop, setCrop, getOpacity, setOpacity, toBuilder |
FPdfTextSpan | getId, getText, getTextRuns, getBounds, replaceText |
TypeScript
// FPdfPageElementgetId(): stringgetType(): PdfObjectTypegetData(): Readonly<PdfObject>getTransform(): IPdfFacadeTransformsetTransform(transform: IPdfFacadeTransform): thissetPosition(left: number, top: number): thissetSize(width: number, height: number): thissetRotation(rotation: number): thissetVisible(visible: boolean): thissetLocked(locked: boolean): thisbringToFront(): thissendToBack(): thisbringForward(): thissendBackward(): thisremove(): voidTypeScript
import '@univerjs-pro/pdfs/facade'const pdf = univerAPI.createPdf({ name: 'Project brief' })const page = pdf.insertPage()page.insertTextBox({ text: 'Hello PDF', left: 36, top: 36 }).setTextStyle({ fontSize: 18, fill: '#274690' })page.insertTable({ rowCount: 2, columnCount: 2, cellTexts: ['Metric', 'Value', 'Users', '42'],})const snapshot = pdf.save()PDF facade enums include PdfAnnotationType, PdfListKind, PdfListPresetId, PdfTextAnchor, and PdfTableCellVerticalAlign through univerAPI.Enum.
For browser printing, see @univerjs-pro/pdfs-print.
@univerjs-pro/pdfsHow is this guide?