> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/file-storage/pdf.md).

# PDF 查看器

### 打开 PDF 查看器

**SDK 函数：** `openPDFViewer`

`openPDFViewer`这是一个将 Base64 编码的 PDF 数据打开到原生 PDF 查看器中的函数。当用户关闭 PDF 查看器时 `'CLOSE'`会返回。

**签名**

```typescript
function openPDFViewer(params: OpenPDFViewerParams): Promise<OpenPDFViewerResult>;
```

**参数**

* params必填

  这是一个包含 PDF 数据和文件名的对象。详细类型请参见下方 `OpenPDFViewerParams`。

**返回值**

* Promise\<OpenPDFViewerResult>

  PDF 查看器关闭后 `'CLOSE'`会返回。

**错误**

| 错误代码                      | 触发条件                      |
| ------------------------- | ------------------------- |
| `INVALID_REQUEST`         | 当请求参数不正确时                 |
| `INVALID_DATA`            | 当 PDF 数据无效时               |
| `PDF_VIEWER_ERROR`        | 在打开 PDF 查看器的过程中发生错误时      |
| `UNSUPPORTED_APP_VERSION` | 当 Toss App 版本低于 5.261.0 时 |

**示例**

{% tabs %}
{% tab title="React" %}

```tsx
import { openPDFViewer } from '@apps-in-toss/web-framework';

async function showPdf() {
  try {
    const result = await openPDFViewer({
      data: 'JVBERi0xLjQK...',
      filename: 'document.pdf',
    });

    if (result === 'CLOSE') {
      console.log('PDF 查看器已关闭。');
    }
  } catch (error) {
    console.error('PDF 查看器错误：', error);
  }
}
```

{% endtab %}

{% tab title="React Native" %}

```tsx
import { openPDFViewer } from '@apps-in-toss/framework';

async function showPdf() {
  try {
    const result = await openPDFViewer({
      data: 'JVBERi0xLjQK...',
      filename: 'document.pdf',
    });

    if (result === 'CLOSE') {
      console.log('PDF 查看器已关闭。');
    }
  } catch (error) {
    console.error('PDF 查看器错误：', error);
  }
}
```

{% endtab %}
{% endtabs %}

### 类型 · 对象

**PDF 查看器参数 (`OpenPDFViewerParams`)**

`openPDFViewer` 这是传递给函数的参数类型。

**签名**

```typescript
interface OpenPDFViewerParams {
  data: string;
  filename?: string;
}
```

**属性**

* datastring必填

  这是以 Base64 格式编码的 PDF 数据字符串。
* filenamestring

  这是 PDF 文件名。

**PDF 查看器结果 (`OpenPDFViewerResult`)**

这是在 PDF 查看器关闭时返回的结果类型。

**签名**

```typescript
type OpenPDFViewerResult = 'CLOSE';
```

**值说明**

| 值         | 说明               |
| --------- | ---------------- |
| `'CLOSE'` | 表示用户关闭了 PDF 查看器。 |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/file-storage/pdf.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
