FPdfParagraph
Facade for one story-backed editable paragraph frame.
Access
Access through:
Inheritance
Extends FPdfPageElement. Its inherited members are available on this object.
Example
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.insertParagraph({ text: 'First paragraph', fontSize: 24,})console.log(paragraph.getBlocks())paragraph.appendBlock({ text: 'Second paragraph', textStyle: { fontSize: 18, bold: true, },})const block = paragraph.getBlocks()[0]paragraph .setBlockText(block.id, 'Updated first paragraph') .setBlockStyle(block.id, { align: 'center' })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
FPdfParagraph.appendBlock
Append one stable paragraph block.
appendBlock(block: IPdfParagraphBlockInput): thisParameters
block— Required. The new block data.
Returns
This paragraph Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.getParagraphs()[0]if (paragraph) { paragraph.appendBlock({ text: 'Last paragraph', textStyle: { fontSize: 16, underline: true, }, })}Types: IPdfParagraphBlockInput
Package: @univerjs-pro/pdfs · Type definitions
FPdfParagraph.getBlocks
Return detached paragraph blocks in story order.
getBlocks(): readonly IPdfParagraphBlockSnapshot[]Returns
The current block snapshots.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.getParagraphs()[0]console.log(paragraph?.getBlocks())Types: IPdfParagraphBlockSnapshot
Package: @univerjs-pro/pdfs · Type definitions
FPdfParagraph.insertBlock
Insert one stable paragraph block at a zero-based index.
insertBlock(index: number, block: IPdfParagraphBlockInput): thisParameters
index— Required. The insertion index.block— Required. The new block data.
Returns
This paragraph Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.getParagraphs()[0]if (paragraph) { paragraph.insertBlock(0, { text: 'Inserted paragraph', textStyle: { fontSize: 20, italic: true, }, })}Types: IPdfParagraphBlockInput
Package: @univerjs-pro/pdfs · Type definitions
FPdfParagraph.removeBlock
Remove one stable paragraph block.
removeBlock(blockId: string): thisParameters
blockId— Required. The stable block ID.
Returns
This paragraph Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.getParagraphs()[0]const block = paragraph?.getBlocks()[0]if (paragraph && block) { paragraph.removeBlock(block.id)}Package: @univerjs-pro/pdfs · Type definitions
FPdfParagraph.setBlockStyle
Apply paragraph layout properties to one stable block.
setBlockStyle(blockId: string, style: IPdfParagraphStyle): thisParameters
blockId— Required. The stable block ID.style— Required. The paragraph style patch.
Returns
This paragraph Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.getParagraphs()[0]const block = paragraph?.getBlocks()[0]if (paragraph && block) { paragraph.setBlockStyle(block.id, { align: 'center', })}Types: IPdfParagraphStyle
Package: @univerjs-pro/pdfs · Type definitions
FPdfParagraph.setBlockText
Replace the text in a generated paragraph block.
setBlockText(blockId: string, text: string): thisParameters
blockId— Required. The stable block ID.text— Required. The replacement text.
Returns
This paragraph Facade for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const paragraph = page.getParagraphs()[0]const block = paragraph?.getBlocks()[0]if (paragraph && block) { paragraph.setBlockText(block.id, 'Updated paragraph')}Package: @univerjs-pro/pdfs · Type definitions
How is this guide?