Skip to content
이 내용이 도움이 되었나요?

PDF 뷰어 열기 (openPDFViewer)

지원환경: React NativeReact Native SDKv2.6.0WebViewWebView SDKv2.6.0
실행환경: Toss AppSandbox App

openPDFViewer는 Base64로 인코딩된 PDF 데이터를 네이티브 PDF 뷰어로 여는 함수예요.
사용자가 PDF 뷰어를 닫으면 'CLOSE'를 반환해요.

시그니처

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

파라미터

  • params필수

    PDF 데이터와 파일 이름을 담은 객체예요. 자세한 타입은 OpenPDFViewerParams를 참고하세요.

반환값

  • Promise<OpenPDFViewerResult>

    PDF 뷰어가 닫히면 'CLOSE'를 반환해요.

에러

에러 코드발생 조건
INVALID_REQUEST요청 파라미터가 올바르지 않을 때
INVALID_DATAPDF 데이터가 유효하지 않을 때
PDF_VIEWER_ERRORPDF 뷰어를 여는 과정에서 오류가 발생했을 때
UNSUPPORTED_APP_VERSION토스앱 버전이 5.261.0보다 낮을 때

예제

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);
  }
}
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);
  }
}

OpenPDFViewerParams

openPDFViewer 함수에 전달하는 파라미터 타입이에요.

시그니처

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

프로퍼티

  • datastring필수

    Base64 형식으로 인코딩된 PDF 데이터 문자열이에요.

  • filenamestring

    PDF 파일 이름이에요.

OpenPDFViewerResult

PDF 뷰어가 닫혔을 때 반환되는 결과 타입이에요.

시그니처

typescript
type OpenPDFViewerResult = 'CLOSE';

값 설명

설명
'CLOSE'사용자가 PDF 뷰어를 닫은 경우예요.