Files
html2pptx/reference/output.md
T

157 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 输出参数 (Output Props)
输出参数用于导出演示文稿,支持 `writeFile()`(写入文件)、`write()`(返回数据)和 `stream()`(返回流)三种方式。
---
## 输出方法
### pptx.writeFile()
```ts
pptx.writeFile(props?: WriteFileProps): Promise<string>
```
- **fileName**:导出文件名
- 类型:`string`
- 默认值:`'Presentation.pptx'`
- **compression**:是否启用压缩
- 类型:`boolean`
- 默认值:`false`
- 说明:可显著减小文件体积,但导出耗时略长
- 始于:v3.5.0
### pptx.write()
```ts
pptx.write(props?: WriteProps): Promise<string | ArrayBuffer | Blob | Uint8Array>
```
- **outputType**:输出类型
- 类型:`WRITE_OUTPUT_TYPE`
- 取值范围:`'arraybuffer' | 'base64' | 'binarystring' | 'blob' | 'nodebuffer' | 'uint8array' | 'STREAM'`
- 默认值:`'blob'`
- **compression**:是否启用压缩
- 类型:`boolean`
- 默认值:`false`
- 始于:v3.5.0
### pptx.stream()
```ts
pptx.stream(props?: WriteBaseProps): Promise<string | ArrayBuffer | Blob | Uint8Array>
```
- **compression**:是否启用压缩
- 类型:`boolean`
- 默认值:`false`
- 始于:v3.5.0
---
## WriteBaseProps
`writeFile()``stream()` 的输出基础属性。
- **compression**:压缩选项
- 类型:`boolean`
- 默认值:`false`
- 始于:v3.5.0
- 说明:启用 Zip 压缩以减小文件体积
---
## WriteProps
继承 `WriteBaseProps`,用于 `write()` 方法。
- **outputType**:输出类型
- 类型:`WRITE_OUTPUT_TYPE`
- 取值范围:`'arraybuffer' | 'base64' | 'binarystring' | 'blob' | 'nodebuffer' | 'uint8array' | 'STREAM'`
- 默认值:`'blob'`
- **compression**:压缩选项
- 类型:`boolean`
- 默认值:`false`
---
## WriteFileProps
继承 `WriteBaseProps`,用于 `writeFile()` 方法。
- **fileName**:导出文件名
- 类型:`string`
- 默认值:`'Presentation.pptx'`
- **compression**:压缩选项
- 类型:`boolean`
- 默认值:`false`
---
## OutputType 枚举
| 常量 | 值 | 说明 |
|---|---|---|
| `OutputType.arraybuffer` | `'arraybuffer'` | ArrayBuffer |
| `OutputType.base64` | `'base64'` | Base64 字符串 |
| `OutputType.binarystring` | `'binarystring'` | 二进制字符串 |
| `OutputType.blob` | `'blob'` | Blob 对象(默认) |
| `OutputType.nodebuffer` | `'nodebuffer'` | Node.js Buffer |
| `OutputType.uint8array` | `'uint8array'` | Uint8Array |
## JSZIP_OUTPUT_TYPE
```ts
type JSZIP_OUTPUT_TYPE = 'arraybuffer' | 'base64' | 'binarystring' | 'blob' | 'nodebuffer' | 'uint8array'
```
## WRITE_OUTPUT_TYPE
```ts
type WRITE_OUTPUT_TYPE = JSZIP_OUTPUT_TYPE | 'STREAM'
```
---
## Presentation 属性
导出前的演示文稿元数据属性。
- **author**:作者
- 类型:`string`
- 说明:演示文稿作者名称
- **company**:公司
- 类型:`string`
- 说明:公司名称
- **layout**:布局名称
- 类型:`string`
- 说明:当前演示文稿布局
- 标准值:`'LAYOUT_4x3'``'LAYOUT_16x9'``'LAYOUT_16x10'``'LAYOUT_WIDE'`
- **rtlMode**:从右向左模式
- 类型:`boolean`
- 默认值:`false`
- **revision**:修订号
- 类型:`string`
- 说明:必须为整数(不含小数点或逗号),否则 PowerPoint 打开时会报错
- **subject**:主题
- 类型:`string`
- 说明:演示文稿主题
- **theme**:主题字体
- 类型:`ThemeProps`
- 子参数:
- **theme.headFontFace**:标题字体(默认 `'Calibri Light'`
- **theme.bodyFontFace**:正文字体(默认 `'Calibri'`
- **title**:演示文稿标题
- 类型:`string`