# 在 Web Component 中整合

- Human documentation: [https://docs.univer.ai/zh-TW/guides/pdfs/getting-started/integrations/web-component](https://docs.univer.ai/zh-TW/guides/pdfs/getting-started/integrations/web-component)

- Agent Markdown: [https://docs.univer.ai/zh-TW/guides/pdfs/getting-started/integrations/web-component.md](https://docs.univer.ai/zh-TW/guides/pdfs/getting-started/integrations/web-component.md)

- Requested language: `zh-TW`

- Content language: `zh-TW`

- Documentation version: `1.2.0`

- Source: [pdfs/getting-started/integrations/web-component.zh-TW.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/pdfs/getting-started/integrations/web-component.zh-TW.mdx)

---

請先閱讀[安裝與基本使用](https://docs.univer.ai/zh-TW/guides/pdfs/getting-started/installation.md)。以下範例透過 Web Component 將 Univer Pdfs 掛載到具有明確高度的容器中。

### 整合步驟

1. 在 `connectedCallback` 中初始化 Univer
2. 在 `disconnectedCallback` 中銷毀 Univer

### 範例程式碼

```typescript
import { UniverLicensePlugin } from '@univerjs-pro/license'
import { UniverPdfsPlugin } from '@univerjs-pro/pdfs'
import { UniverPdfsUIPlugin } from '@univerjs-pro/pdfs-ui'
import PdfsUIzhTW from '@univerjs-pro/pdfs-ui/locale/zh-TW'
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'
import { FUniver } from '@univerjs/core/facade'
import DesignzhTW from '@univerjs/design/locale/zh-TW'
import { UniverUIPlugin } from '@univerjs/ui'
import UIzhTW from '@univerjs/ui/locale/zh-TW'

import '@univerjs/design/lib/index.css'
import '@univerjs/ui/lib/index.css'
import '@univerjs-pro/pdfs-ui/lib/index.css'

import '@univerjs-pro/pdfs/facade'

class UniverEditorElement extends HTMLElement {
  private univer?: Univer

  connectedCallback() {
    const container = this

    const univer = new Univer({
      locale: LocaleType.ZH_TW,
      locales: {
        [LocaleType.ZH_TW]: mergeLocales(
          DesignzhTW,
          UIzhTW,
          PdfsUIzhTW,
        ),
      },
    })

    univer.registerPlugin(UniverLicensePlugin, {
      license: 'your license.txt',
    })
    univer.registerPlugin(UniverUIPlugin, { container })
    univer.registerPlugin(UniverPdfsPlugin)
    univer.registerPlugin(UniverPdfsUIPlugin)

    const univerAPI = FUniver.newAPI(univer)
    univerAPI.createPdf({ name: 'Untitled PDF' })
    this.univer = univer
  }

  disconnectedCallback() {
    this.univer?.dispose()
    this.univer = undefined
  }
}

customElements.define('univer-pdfs-editor', UniverEditorElement)
```

```html
<univer-pdfs-editor style="display: block; height: 600px"></univer-pdfs-editor>
```
