# 文字與清單

> 插入並編輯文字方塊、段落區塊和語意化 PDF 清單。

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

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

- Requested language: `zh-TW`

- Content language: `zh-TW`

- Documentation version: `1.2.0`

- Source: [pdfs/features/core/text-and-lists.zh-TW.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/pdfs/features/core/text-and-lists.zh-TW.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()`。
