# 文本与列表

> 插入并编辑文本框、段落块和语义化 PDF 列表。

- Human documentation: [https://docs.univer.ai/zh-CN/guides/pdfs/features/core/text-and-lists](https://docs.univer.ai/zh-CN/guides/pdfs/features/core/text-and-lists)

- Agent Markdown: [https://docs.univer.ai/zh-CN/guides/pdfs/features/core/text-and-lists.md](https://docs.univer.ai/zh-CN/guides/pdfs/features/core/text-and-lists.md)

- Requested language: `zh-CN`

- Content language: `zh-CN`

- Documentation version: `1.0.0-rc.0`

- Source: [pdfs/features/core/text-and-lists.zh-CN.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/pdfs/features/core/text-and-lists.zh-CN.mdx)

---

PDF 文本可以是简单的可编辑文本框、基于 story 的段落框架或语义化列表。

## 文本框

```ts
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?)` 可向整个文本框或 UTF-16 范围应用样式；范围包含起始位置，不包含结束位置。

## 段落

段落块具有稳定 ID。更新文本、样式或顺序前，请先通过 `getBlocks()` 读取段落块。

```ts
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' })
}
```

## 语义化列表

```ts
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)
```

列表层级为 `0` 到 `8`。提升层级时，前面必须存在可作为父级的项目；`setStartNumber()` 仅适用于有序列表。

文本框还提供 `getTextRuns()`、`getTextAnchor()` 和 `setTextAnchor()`。段落提供 `insertBlock()`、`appendBlock()`、`setBlockText()`、`setBlockStyle()` 和 `removeBlock()`。
