Text and Lists
Insert and edit text boxes, paragraph blocks, and semantic PDF lists.
PDF text can be a simple editable text box, a story-backed paragraph frame, or a semantic list.
Text boxes
const textBox = page.insertTextBox({ text: 'Quarterly review', left: 36, top: 36, width: 280, height: 48, fontSize: 20,})textBox.setTextStyle({ bold: true, fill: '#1d4ed8' })textBox.setTextStyle({ italic: true }, { start: 0, end: 9 })setTextStyle(style, range?) applies a style to the whole box or to a UTF-16 range whose start is inclusive and end is exclusive.
Paragraphs
Paragraph blocks have stable IDs. Read them with getBlocks() before updating text, style, or order.
const paragraph = page.insertParagraph({ text: 'Release summary', left: 36, top: 108, width: 280, height: 96,})paragraph.appendBlock({ text: 'Approved for publication', textStyle: { italic: true },})const [block] = paragraph.getBlocks()if (block) { paragraph.setBlockStyle(block.id, { align: 'center' })}Semantic lists
const list = page.insertList({ text: 'Verify content', kind: univerAPI.Enum.PdfListKind.ORDERED, preset: univerAPI.Enum.PdfListPresetId.ORDERED_NUMBER_ALPHA, left: 36, top: 228, width: 280, height: 120,})list.insertItem(1, { text: 'Export final PDF' })list.insertItem(2, { text: 'Archive source', level: 1 })list.setStartNumber(3)List levels range from 0 through 8. Increasing a level requires a preceding item that can serve as its parent; setStartNumber() is available only for ordered lists.
Text boxes also expose getTextRuns(), getTextAnchor(), and setTextAnchor(). Paragraphs expose insertBlock(), appendBlock(), setBlockText(), setBlockStyle(), and removeBlock().
How is this guide?