ComPDF React Native - v3.0.0
    Preparing search index...

    Class CPDFReaderView

    Native PDF reader component for viewing and editing a document.

    3.0.0

    Supported on Android and iOS. Platform-specific methods document their limitations.

    Hierarchy

    Index

    Annotations

    Constructors

    Content Editing

    Deprecated

    Dialogs and UI

    Digital Signatures

    Document Lifecycle

    Events

    Forms

    Methods

    Navigation

    View Settings

    Annotations

    _annotationsHistoryManager: CPDFAnnotationHistoryManager
    • Used to add a specified annotation type when touching the page in annotation mode This method is only available in [CPDFViewMode.ANNOTATIONS] mode.

      Parameters

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setAnnotationMode(CPDFAnnotationType.HIGHLIGHT);
      
    • Get the type of annotation added to the current touch page. This method is only available in [CPDFViewMode.ANNOTATIONS] mode.

      Returns Promise<CPDFAnnotationType>

      A promise that resolves to the current annotation mode.

      const annotationMode = await pdfReaderRef.current?.getAnnotationMode();
      
    • Save the current ink annotation.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.saveCurrentInk();
      
    • Save the current pencil annotation.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.saveCurrentPencil();
      
    • Sets whether annotations are visible.

      Parameters

      • visible: boolean

        whether annotations should be visible

      Returns Promise<void>

      await pdfReaderRef.current?.setAnnotationsVisible(true);
      
    • Gets whether annotations are visible.

      Returns Promise<boolean>

      const visible = await pdfReaderRef.current?.isAnnotationsVisible();
      
    • Displays the default properties panel for the specified annotation type.

      Only some annotation types are supported. Please refer to the documentation for the list of supported types.

      Parameters

      • type: CPDFAnnotationType

        The type of annotation for which to display the properties panel.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showDefaultAnnotationPropertiesView(CPDFAnnotationType.HIGHLIGHT);
      
    • Displays the properties panel for the specified annotation.

      Only some annotation types are supported. Please refer to the documentation for the list of supported types.

      Parameters

      • annotation: CPDFAnnotation

        The annotation for which to display the properties panel.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showAnnotationPropertiesView(annotation);
      
    • Pre-configures the next stamp annotation to be inserted when the user taps on the page.

      Parameters

      • options: CPDFPrepareNextStampOptions

        An object containing exactly one of the following properties:

        • imagePath Path to an image stamp.

        • Android: file path or drawable resource name

        • iOS: file path or bundled image name

        • standardStamp Built-in standard stamp enum value (for example, CPDFStandardStamp.Approved).

        • textStamp A CPDFTextStamp instance that defines custom text, colors, font size, and other properties.

      Returns Promise<void>

      A promise that resolves when the operation completes. A Promise<void> that resolves when the native side has been notified.

      Call this method after entering stamp creation mode to specify which type of stamp (image / standard / text) should be inserted on the next tap.

      Exactly one of imagePath, standardStamp, or textStamp must be provided. Providing none or more than one will result in an error.

      Throws an Error if the "exactly one parameter" rule is violated. The error message is in English.

      // Prepares an image stamp for the next tap
      await pdfReaderRef.current?.prepareNextStamp({ imagePath: '/path/to/stamp.png' });

      // Prepares a standard "Approved" stamp for the next tap
      await pdfReaderRef.current?.prepareNextStamp({standardStamp: CPDFStandardStamp.Approved});

      // Prepares a custom text stamp for the next tap
      await pdfReaderRef.current?.prepareNextStamp({
      textStamp: {
      content: "ComPDFKit",
      date: CPDFDateUtil.getTextStampDate({
      timeSwitch: true,
      dateSwitch: true,
      }),
      color: CPDFTextStampColor.blue,
      shape: CPDFTextStampShape.leftTriangle,
      },
      });
    • Fetches the default annotation style. Use this after the CPDFReaderView is initialized to retrieve the current default annotation style.

      Returns Promise<CPDFAnnotationAttr>

      The current default annotation style; returns an empty object if the native view is unavailable.

      const defaultStyle = await pdfReaderRef.current?.fetchDefaultAnnotationStyle();
      
    • Updates the default annotation style. When updating annotation styles, you can pass only the properties that need to be modified, and other properties will remain unchanged. All HexColor values are normalized to ARGB before being sent to native.

      Parameters

      Returns Promise<void>

      A promise that resolves when the operation completes.

      const noteAttr : CPDFTextAttr = {
      type: 'note',
      color: '#FF0000',
      alpha: 100
      }
      await pdfReaderRef.current?.updateDefaultAnnotationStyle(noteAttr);

    Constructors

    Content Editing

    _editManager: CPDFEditManager
    • Displays the properties panel for the specified edit area. support:

      • CPDFEditType.TEXT
      • CPDFEditType.IMAGE

      Parameters

      • editArea: CPDFEditArea

        The edit area for which to display the properties panel.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showEditAreaPropertiesView(editArea);
      

    Deprecated

    • Returns Promise<boolean>

      A promise that resolves to true when all annotations are removed; otherwise, false.

      Use _pdfDocument.removeAllAnnotations() instead.

      Delete all comments in the current document

      const removeResult = await pdfReaderRef.current?.removeAllAnnotations();
      
    • Parameters

      • xfdfFile: string

        Path of the XFDF file to be imported.

      Returns Promise<boolean>

      true if the import is successful; otherwise, false.

      Use _pdfDocument.importAnnotations() instead.

      Imports annotations from the specified XFDF file into the current PDF document.

      // Android - assets file
      const testXfdf = 'file:///android_asset/test.xfdf';
      const importResult = await pdfReaderRef.current?.importAnnotations(testXfdf);

      // Android - file path
      const testXfdf = '/data/user/0/com.compdfkit.reactnative.example/xxx/xxx.xfdf';
      const importResult = await pdfReaderRef.current?.importAnnotations(testXfdf);

      // Android - Uri
      const xfdfUri = 'content://xxxx'
      const importResult = await pdfReaderRef.current?.importAnnotations(xfdfUri);

      // iOS
    • Returns Promise<string>

      The path of the XFDF file if export is successful; an empty string if the export fails.

      Use _pdfDocument.exportAnnotations() instead.

      Exports annotations from the current PDF document to an XFDF file.

      const exportXfdfFilePath = await pdfReaderRef.current?.exportAnnotations();
      
    • Parameters

      Returns Promise<void>

      Use setViewMode() instead.

    • Returns Promise<void>

      Use reloadPagesPreservingPosition() instead.

    Dialogs and UI

    • Displays the "Add Watermark" view, where users can add watermarks to the document.

      Parameters

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showAddWatermarkView();
      
    • Displays the document security settings view, allowing users to configure document security options.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showSecurityView();
      
    • Displays the display settings view, where users can configure options such as scroll direction, scroll mode, and themes.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showDisplaySettingView();
      
    • Displays the document information view, where users can inspect document metadata.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showDocumentInfoView();
      
    • Enters snip mode, allowing users to capture screenshots.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.enterSnipMode();
      
    • Exits snip mode, stopping the screenshot capture.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.exitSnipMode();
      
    • Dismiss the context menu if it is displayed.

      Returns Promise<void>

      Dismiss the context menu if it is displayed.

      await pdfReaderRef.current?.dismissContextMenu();
      

    Digital Signatures

    • Verify the digital signature status of the document. If the document contains a digital signature, a status bar will be displayed at the top of the document.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.verifyDigitalSignatureStatus();
      
    • Hide the digital signature status view.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.hideDigitalSignStatusView();
      

    Document Lifecycle

    _pdfDocument: CPDFDocument
    • Save the document and return whether it is saved successfully.

      Returns Promise<boolean>

      true or false

      const saveResult = await pdfReaderRef.current.save();
      
    • Returns Promise<boolean>

      Returns a Promise indicating if the document has been modified. true: The document has been modified, false: The document has not been modified. If the native view reference cannot be found, a rejected Promise will be returned.

      Use _pdfDocument.hasChange() instead.

      Checks whether the document has been modified

      const hasChange = await pdfReaderRef.current?.hasChange();
      
    • Reloads all pages in the readerview.

      Returns Promise<void>

      A promise that resolves when the operation completes.

    • Reloads all pages while preserving the current reading position.

      On Android, this keeps the current viewport anchored to the same visual position after the refresh. For example, if the viewer is currently showing page 2 at about 20% scroll progress, the same position remains visible after reloading. On iOS, this falls back to reloadPages() because the native implementation does not expose a position-preserving reload path.

      Returns Promise<void>

      A promise that resolves when the operation completes.

    Events

    • Register an event listener for a specific event with type-safe callbacks.

      Type Parameters

      Parameters

      • event: K

        The event type to listen for

      • callback: (eventData: CPDFEventDataMap[K]) => void

        The callback function with typed event data

      Returns void

      // Annotation created event - returns CPDFAnnotation
      pdfReaderRef.current?.addEventListener(CPDFEvent.ANNOTATIONS_CREATED, (annotation) => {
      console.log('Annotation created:', annotation.type);
      });

      // Form field selected event - returns CPDFWidget
      pdfReaderRef.current?.addEventListener(CPDFEvent.FORM_FIELDS_SELECTED, (widget) => {
      console.log('Form field selected:', widget.type);
      });

      // Editor selection - returns CPDFEditArea | null
      pdfReaderRef.current?.addEventListener(CPDFEvent.EDITOR_SELECTION_DESELECTED, (editArea) => {
      if (editArea) {
      console.log('Edit area deselected');
      }
      });
    • Remove an event listener for a specific event.

      Type Parameters

      Parameters

      • event: K

        The event type to stop listening for

      • callback: (eventData: CPDFEventDataMap[K]) => void

        The callback function to remove

      Returns void

    Forms

    • set current form creation mode. This method is only available in [CPDFViewMode.FORMS] mode.

      Parameters

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setFormCreationMode(CPDFWidgetType.TEXT_FIELD);
      
    • get current form creation mode. This method is only available in [CPDFViewMode.FORMS] mode.

      Returns Promise<CPDFWidgetType>

      get current form creation mode.

      const formCreationMode = await pdfReaderRef.current?.getFormCreationMode();
      
    • Exits form creation mode. This method is only available in [CPDFViewMode.FORMS] mode.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.exitFormCreationMode();
      
    • Displays the properties panel for the specified form field widget.

      Only some widget types are supported. Please refer to the documentation for the list of supported types.

      Parameters

      • widget: CPDFWidget

        The form widget whose properties or appearance will be updated.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showWidgetPropertiesView(widget);
      
    • Fetches the default widget style.

      Returns Promise<CPDFWidgetAttr>

      The current default widget style; returns an empty object if the native view is unavailable.

      const defaultWidgetStyle = await pdfReaderRef.current?.fetchDefaultWidgetStyle();
      
    • Updates the default widget style. When updating form fields, you can pass only the properties that need to be modified, and other properties will remain unchanged. All HexColor values are normalized to ARGB before being sent to native.

      Parameters

      Returns Promise<void>

      A promise that resolves when the default widget style is updated.

      await pdfReaderRef.current?.updateDefaultWidgetStyle({
      type: 'textField',
      fillColor: '#DDE9FF',
      borderColor: '#1460F3'
      });
      • CPDFTextFieldAttr
      • CPDFCheckBoxAttr
      • CPDFRadioButtonAttr
      • CPDFListBoxAttr
      • CPDFComboBoxAttr
      • CPDFPushButtonAttr
      • CPDFSignatureWidgetAttr

    Methods

    • Pre-configure the next signature annotation to be inserted when the user taps the page. only use in signature creation mode. [CPDFAnnotationType.signature]

      Parameters

      • signaturePath: string

      Returns Promise<void>

      // first enter signature creation mode await controller.setAnnotationMode(CPDFAnnotationType.signature);

      // then prepare the signature image path await controller.prepareNextSignature('/path/to/signature.png');

      // now, when the user taps the page, the signature will be inserted using the specified image

      @param signaturePath The local path of the signature image to insert.
      @returns A promise that resolves when the operation completes.
      @group Digital
    • Pre-configure the next image annotation to be inserted when the user taps the page.

      Parameters

      • imagePath: string

        The path of the image to be used for the next image annotation.

      Returns Promise<void>

      // first enter image creation mode await pdfReaderRef.current?.setAnnotationMode(CPDFAnnotationType.PICTURES);

      // then prepare the image path await pdfReaderRef.current?.prepareNextImage('/path/to/image.png');

      // now, when the user taps the page, the image annotation will be inserted using the specified image

      @returns A promise that resolves when the operation completes.
      @group

    Navigation

    • Jump to the index page.

      Parameters

      • pageIndex: number

        The index of the page to jump.

      • options: { rectList?: CPDFRectF[] } = {}

        Options for page display

        • OptionalrectList?: CPDFRectF[]

          The rects to be visible in the page. The rect is in PDF coordinate system.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setDisplayPageIndex(1);
      
    • get current page index

      Returns Promise<number>

      A promise that resolves to the current zero-based page index.

      const pageIndex = await pdfReaderRef.current?.getCurrentPageIndex();
      
    • Displays the thumbnail view. When [editMode] is true, the page enters edit mode, allowing operations such as insert, delete, extract, etc.

      Parameters

      • editMode: boolean

        Whether to enable edit mode

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showThumbnailView(true);
      
    • Displays the BOTA view, which includes the document outline, bookmarks, and annotation list.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.showBotaView();
      
    • Show the search text view.

      Returns Promise<void>

      Show the search text view.

      await pdfReaderRef.current?.showSearchTextView();
      
    • Hide the search text view.

      Returns Promise<void>

      Hide the search text view.

      await pdfReaderRef.current?.hideSearchTextView();
      

    View Settings

    • Set the reading area spacing.

      Parameters

      • left: number

        The left reading-area margin.

      • top: number

        The top reading-area margin.

      • right: number

        The right reading-area margin.

      • bottom: number

        The bottom reading-area margin.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setMargins(10,10,10,10);
      
    • Set the page scale Value Range: 1.0~5.0

      Parameters

      • scale: number

        The zoom scale to apply.

      Returns Promise<void>

      Returns a Promise.

      await pdfReaderRef.current?.setScale(2.0);
      
    • Get the current page scale

      Returns Promise<number>

      Returns the zoom ratio of the current page.

      const scale = await pdfReaderRef.current?.getScale();
      
    • Whether allow to scale. Default : true

      Parameters

      • canScale: boolean

        Whether pinch-to-zoom is enabled.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setCanScale(false);
      
    • Sets background color of reader. The color of each document space will be set to 75% of [color] transparency

      Parameters

      • theme: string

        The reading background theme to apply.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setReadBackgroundColor(CPDFThemes.LIGHT);
      
    • Set the background color of the reader.

      Parameters

      • color: string

        The background color to set (in hex format).

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setBackgroundColor('#285BA8FF');
      
    • Get background color of reader.

      Returns Promise<string>

      A promise that resolves to the current reading background theme.

      CPDFThemes theme = await pdfReaderRef.current?.getReadBackgroundColor();
      
    • Sets whether to display highlight Form Field.

      Parameters

      • isFormFieldHighlight: boolean

        true to display highlight Form Field.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setFormFieldHighlight(true);
      
    • Whether to display highlight Form Field.

      Returns Promise<boolean>

      A promise that resolves to whether form field highlighting is enabled.

      const isFormFieldHighlight = await pdfReaderRef.current?.isFormFieldHighlight();
      
    • Sets whether to display highlight Link.

      Parameters

      • isLinkHighlight: boolean

        Whether to highlight Link.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setLinkHighlight(true);
      
    • Whether to display highlight Link.

      Returns Promise<boolean>

      A promise that resolves to whether link highlighting is enabled.

      const isLinkHighlight = await pdfReaderRef.current?.isLinkHighlight();
      
    • Sets whether it is vertical scroll mode.

      Parameters

      • isVerticalMode: boolean

        Whether it is vertical scroll mode.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setVerticalMode(true);
      
    • Whether it is vertical scroll mode.

      Returns Promise<boolean>

      A promise that resolves to whether vertical scrolling is enabled.

      await pdfReaderRef.current?.isVerticalMode();
      
    • Sets the spacing between pages. This method is supported only on the [Android] platform.

      • For the [iOS] platform, use the [setMargins] method instead. The spacing between pages is equal to the value of [CPDFEdgeInsets.top].

      Parameters

      • pageSpacing: number

        The space between pages, in pixels.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setPageSpacing(10);
      
    • Sets whether it is continuous scroll mode.

      Parameters

      • isContinueMode: boolean

        Whether it is continuous scroll mode.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setContinueMode(true);
      
    • Whether it is continuous scroll mode.

      Returns Promise<boolean>

      A promise that resolves to whether continuous scrolling is enabled.

      await pdfReaderRef.current?.isContinueMode();
      
    • Sets whether it is double page mode.

      Parameters

      • isDoublePageMode: boolean

        Whether it is double page mode.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setDoublePageMode(true);
      
    • Whether it is double page mode.

      Returns Promise<boolean>

      Returns true if double page display is enabled, otherwise returns false

      await pdfReaderRef.current?.isDoublePageMode();
      
    • Sets whether it is cover page mode.

      Parameters

      • isCoverPageMode: boolean

        Whether to display the document in cover form

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setCoverPageMode(true);
      
    • Whether it is cover page mode.

      Returns Promise<boolean>

      Returns true if the document cover is displayed, otherwise returns false

      await pdfReaderRef.current?.isCoverPageMode();
      
    • Sets whether it is crop mode.

      Parameters

      • isCropMode: boolean

        Whether it is crop mode.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setCropMode(true);
      
    • Whether it is crop mode.

      Returns Promise<boolean>

      Returns true if the current mode is clipping mode, otherwise returns false

      await pdfReaderRef.current?.isCropMode();
      
    • In the single page mode, set whether all pages keep the same width and the original page keeps the same width as readerView.

      Parameters

      • isPageSameWidth: boolean

        true: All pages keep the same width, the original state keeps the same width as readerView; false: Show in the actual width of page

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setPageSameWidth(true);
      
    • Gets whether the specified [pageIndex] is displayed on the screen

      Parameters

      • pageIndex: number

        The zero-based page index to check.

      Returns Promise<boolean>

      A promise that resolves to whether the specified page is currently visible.

      const isPageInScreen = await pdfReaderRef.current?.isPageInScreen(1);
      
    • Sets whether to fix the position of the non-swipe direction when zooming in for reading.

      Parameters

      • isFixedScroll: boolean

        Whether to fix scrolling

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setFixedScroll(true);
      
    • Switch the mode displayed by the current CPDFReaderWidget. Please see [CPDFViewMode] for available modes.

      Parameters

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.setViewMode(CPDFViewMode.VIEWER);
      
    • Get the currently displayed mode.

      Returns Promise<CPDFViewMode>

      A promise that resolves to the current view mode.

      const mode = await pdfReaderRef.current?.getViewMode();
      
    • Clear the display area, making it completely white without displaying any content.

      Returns Promise<void>

      A promise that resolves when the operation completes.

      await pdfReaderRef.current?.clearDisplayRect();