# 注釈とネイティブテキスト

> 対応する PDF 注釈を挿入し、インポートしたネイティブテキストを編集可能なテキストボックスに昇格します。

- Human documentation: [https://docs.univer.ai/ja-JP/guides/pdfs/features/core/annotations-and-native-text](https://docs.univer.ai/ja-JP/guides/pdfs/features/core/annotations-and-native-text)

- Agent Markdown: [https://docs.univer.ai/ja-JP/guides/pdfs/features/core/annotations-and-native-text.md](https://docs.univer.ai/ja-JP/guides/pdfs/features/core/annotations-and-native-text.md)

- Requested language: `ja-JP`

- Content language: `ja-JP`

- Documentation version: `1.2.0`

- Source: [pdfs/features/core/annotations-and-native-text.ja-JP.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/pdfs/features/core/annotations-and-native-text.ja-JP.mdx)

---

編集可能な注釈は永続オーバーレイです。インポートしたテキストは、表示中のテキスト範囲を Facade で昇格するまでネイティブのままです。

## 注釈を挿入する

```ts
const highlight = page.insertAnnotation({
  annotationType: univerAPI.Enum.PdfAnnotationType.HIGHLIGHT,
  left: 36,
  top: 72,
  width: 180,
  height: 18,
  markup: {
    color: '#fde047',
    opacity: 0.6,
  },
})
```

Facade から挿入できるのは、ハイライト、下線、取り消し線、波線、インク注釈です。インクには空でないパスが必要です。コアのその他の注釈サブタイプはこの API では挿入できません。

## 注釈のデータとスタイルを取得する

```ts
const markup = highlight.getMarkup()
const style = highlight.getStyle()

highlight.setStyle({
  stroke: { color: '#ca8a04', width: 1 },
  opacity: 0.75,
})
```

`getMarkup()` と `getInk()` は PDF ポイントの切り離された形状を返します。`setStyle()` は対応する塗り、線、透明度を更新します。透明度は `0` から `1` です。

## インポートしたネイティブテキストを置き換える

```ts
const matchingSpan = page
  .getTextSpans()
  .find((span) => span.getText().includes('Draft'))

if (matchingSpan) {
  const textBox = matchingSpan.replaceText('Final')
  textBox.setTextStyle({ bold: true })
}
```

`getTextSpans()` は、現在表示され抑制されていないネイティブテキストのスナップショットを返します。`replaceText()` はソース操作を不可分に抑制し、取得した位置に編集可能な `FPdfTextBox` を挿入します。

`FPdfTextSpan` はスナップショットハンドルです。置き換え後は無効になるため、次の操作前に `getTextSpans()` を再度列挙してください。
