---
title: "使用页眉和页脚扩展您的 EPUB 导出功能"
description: "了解如何使用 Export EPUB 扩展自定义 EPUB 导出的页眉和页脚。"
canonical_url: "https://tiptap.zhcndoc.com/conversion/export/epub/headers-footers"
---

# 使用页眉和页脚扩展您的 EPUB 导出功能

了解如何使用 Export EPUB 扩展自定义 EPUB 导出的页眉和页脚。

- **1. 激活试用或订阅**

  先在您的账户中开启[免费试用](https://cloud.tiptap.dev/v2?trial=true)或[订阅入门计划](https://cloud.tiptap.dev/v2/billing)。
- **2. 从私有注册表安装**

  要安装此前端扩展，请按照[设置指南](https://tiptap.zhcndoc.com/guides/pro-extensions.md)认证并登录 Tiptap 的私有 npm 注册表。

`@tiptap-pro/extension-export-epub` 扩展内置了对自定义导出文档页眉和页脚的支持。您可以为首页、奇数页和偶数页分别配置不同的页眉和页脚。

## Header Configuration

The `headers` object allows you to customize the headers of exported EPUB documents:

| Property             | Type      | Description                                                                                                                                                                                     |
| -------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `evenAndOddHeaders`  | `boolean` | Whether to use different headers for odd and even pages                                                                                                                                         |
| `differentFirstPage` | `boolean` | Whether to use a different header on the first page. When set to `true`, the first page uses the `first` value instead of `default`.                                                            |
| `default`            | `string`  | The standard default header for each page, or the header for odd pages when `evenAndOddHeaders` is enabled. Supports plain text strings or serialized Tiptap JSONContent for richer formatting. |
| `first`              | `string`  | The header for the first page, used only when `differentFirstPage` is `true`. Supports plain text strings or serialized Tiptap JSONContent for richer formatting.                               |
| `even`               | `string`  | The header for even pages, used only when the `evenAndOddHeaders` option is enabled. Supports plain text strings or serialized Tiptap JSONContent for richer formatting.                        |

When using plain text, a simple unstyled header will be generated. When using serialized Tiptap JSONContent (via `JSON.stringify()`), rich formatting such as bold, italic, and links can be preserved.

## 页脚配置

`footers` 对象允许您自定义导出 EPUB 文档的页脚：

| 属性                   | 类型        | 说明                                                                                  |
| -------------------- | --------- | ----------------------------------------------------------------------------------- |
| `evenAndOddFooters`  | `boolean` | 是否为奇数页和偶数页使用不同的页脚                                                                   |
| `differentFirstPage` | `boolean` | 是否首页使用不同的页脚。为 `true` 时，首页采用 `first` 值，而非 `default`。                                 |
| `default`            | `string`  | 每页的标准默认页脚，或开启 `evenAndOddFooters` 时奇数页的页脚。支持纯文本字符串或序列化的 Tiptap JSONContent 用于丰富格式。  |
| `first`              | `string`  | 首页的页脚，仅当 `differentFirstPage` 为 `true` 时使用。支持纯文本字符串或序列化的 Tiptap JSONContent 用于丰富格式。 |
| `even`               | `string`  | 偶数页的页脚，仅当 `evenAndOddFooters` 选项启用时使用。支持纯文本字符串或序列化的 Tiptap JSONContent 用于丰富格式。      |

使用纯文本时，将生成简单无样式的页脚。使用序列化的 Tiptap JSONContent（通过 `JSON.stringify()`）时，可保留加粗、斜体、链接等丰富格式。

## 完整示例

```js
import { ExportEpub } from '@tiptap-pro/extension-export-epub'

const editor = new Editor({
  extensions: [
    // 其他扩展...
    ExportEpub.configure({
      token: 'YOUR_TOKEN',
      headers: {
        evenAndOddHeaders: true,
        default: '我的文档 - 机密',
        first: '欢迎阅读我的文档',
        even: '我的文档 - 偶数页',
      },
      footers: {
        evenAndOddFooters: true,
        default: '公司名称 - 版权所有',
        first: '草稿版本 1.0',
        even: '公司名称 - 偶数页脚',
      },
    }),
    // 其他扩展...
  ],
})

// 导出带有页眉和页脚的 EPUB
editor
  .chain()
  .exportEpub({
    onCompleteExport(result) {
      const url = URL.createObjectURL(result)
      const a = document.createElement('a')

      a.href = url
      a.download = '带页眉的文档.epub'
      a.click()

      URL.revokeObjectURL(url)
    },
  })
  .run()
```

## 简单的页眉和页脚

如果您不需要奇偶页不同的页眉，可以只提供 `default` 值：

```js
ExportEpub.configure({
  token: 'YOUR_TOKEN',
  headers: {
    default: '我的文档标题',
  },
  footers: {
    default: '页面页脚 - 公司名称',
  },
})
```
