Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@compdfkit_pdf_sdk/react_native

ComPDFKit694SEE LICENSE IN LICENSE2.4.7TypeScript support: included

ComPDFKit for React Native is a comprehensive SDK that allows you to quickly add PDF functionality to Android, iOS, and React Native applications.

react-native, ios, android, pdf, cross-platform, pdf-viewer, pdf-document, pdf-editor, compdfkit

readme

ComPDFKit React-Native PDF Library

About

ComPDFKit for React Native, developed by ComPDF, enables developers to quickly and seamlessly integrate advanced PDF features, such as viewing, annotating, editing, and signing PDFs, into any iOS and Android application. And we provide a 30-day free trial license to test your projects

For more information, please visit our developer guides.

Contents

Prerequisites

Before starting the integration, please ensure the following prerequisites are met:

Get ComPDFKit License Key

ComPDF offers a 30-day free trial license for testing your project. Get one online without contacting sales.

If you require advanced PDF features beyond the free trial license, please contact us to obtain a commercial license.

Download the PDF SDK

Download the ComPDFKit ReactNative PDF SDK from Github or NPM.

System Requirements

Android

Please install the following required packages:

Operating Environment Requirements:

  • Android minSdkVersion of 21 or higher.
  • ComPDFKit SDK 2.0.1 or higher.

iOS

Please install the following required packages:

Operating Environment Requirements:

  • ComPDFKit SDK 2.0.1 or higher.
  • React Native dependency to version 3.0.0 or higher.
  • iOS 12.0 or higher.

Build a React Native PDF Viewer with ComPDFKit PDF SDK

image

Creating a New Project

Let's create a simple app that integrates ComPDFKit for React Native.

  1. In the terminal app, change the current working directory to the location you wish to save your project. In this example, we’ll use the ~/Documents/ directory:

    cd ~/Documents
  2. Create the React Native project by running the following command:

    react-native init MyApp
  3. In the terminal app, change the location of the current working directory inside the newly created project:

    cd MyApp

Expo

If you’re using Expo, refer to the guides post that explains how to use ComPDFKit ReactNative SDK with Expo.

Installing-the-ComPDFKit-Dependency

You can integrate the SDK in two ways:

  • Through ComPDFKit GitHub repo:

    In MyApp folder, install @compdfkit_pdf_sdk/react_native by calling:

    yarn add github:ComPDFKit/compdfkit-pdf-sdk-react-native
  • Through ComPDFKit npm package:

    In MyApp folder, install run the following commands:

    yarn add @compdfkit_pdf_sdk/react_native

Android

  1. open android/app/src/main/AndroidManifest.xml , add Internet Permission and Storage Permission
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.compdfkit.flutter.example">

+    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- Required to read and write documents from device storage -->
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

        <!-- Optional settings -->
+    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

    <application
+    android:requestLegacyExternalStorage="true"
        ...>
    ...
    </application>
</manifest>
  1. Copy the sample pdf file to the assets directory
demo-android-2
  1. Replace App.js (or App.tsx) with what is shown for Usage-Example
  2. Finally in the root project directory, run react-native run-android.

iOS

  1. Open your project’s Podfile in a text editor:
open ios/Podfile
  1. Add the following line to the target 'MyApp' do ... end block:
target 'MyApp' do
    # ...
+  pod "ComPDFKit", podspec:'https://file.compdf.com/cocoapods/ios/compdfkit_pdf_sdk/2.4.7/ComPDFKit.podspec'
+  pod "ComPDFKit_Tools", podspec:'https://file.compdf.com/cocoapods/ios/compdfkit_pdf_sdk/2.4.7/ComPDFKit_Tools.podspec'
    # ...
end

Note: If SSL network requests fail to download the ComPDFKit library when you run pod install, you can use the following method instead.

target 'MyApp' do
    # ...
+  pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.4.7'
+  pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.4.7'
    # ...
end
  1. In the ios folder, run pod install.
  2. Open your project’s Workspace in Xcode:

    open ios/MyApp.xcworkspace

    Make sure the deployment target is set to 12.0 or higher:

    1-1

  3. Add the PDF document you want to display to your application by dragging it into your project. On the dialog that’s displayed, select Finish to accept the default integration options. You can use "PDF_Document.pdf" as an example.

<key>NSCameraUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSMicrophoneUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>Your consent is required before you could access the function.</string>

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
  1. Replace App.js (or App.tsx) with what is shown for Usage-Example
  2. Finally in the root project directory, run react-native run-ios.

Apply the License Key

If you haven't get a license key, please check out how to obtain a license key.

ComPDFKit PDF SDK currently supports two authentication methods to verify license keys: online authentication and offline authentication.

Learn about:

What is the authentication mechanism of ComPDFKit's license?

What are the differences between Online Authentication and Offline Authentication?

Accurately obtaining the license key is crucial for the application of the license.

Android

  1. In the email you received, locate the XML file containing the license key.

  2. Copy the license_key_rn.xml file into the following directory:android/app/src/main/assets/

  1. Initialize the SDK:
ComPDFKit.initWithPath('assets://license_key_rn.xml');

iOS

  1. Use Xcode to copy the license_key_rn.xmlfile into your project’sios/directory.
  1. Initialize the SDK:
// Copy the license_key_rn_ios.xml file into your iOS project directory (or a readable location):
ComPDFKit.initWithPath('license_key_rn.xml');

Alternative Method

You can also store the License file in the device’s local storage and initialize the SDK using its file path:

// Obtain the License file through the local storage path of the device for initialization
ComPDFKit.initWithPath('/data/data/0/your_packages/files/license_key_rn.xml');

Usage-Example

After installing from NPM or GitHub, replace App.tsx with the following code.

Make sure to follow the above steps to copy the sample document into your Android or iOS project.

Here is the sample code for App.tsx:

/**
 * Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
 *
 * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
 * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
 * This notice may not be removed from this file.
 */

import React, { Component } from 'react';
import {
  SafeAreaView
} from 'react-native';
import { ComPDFKit, CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';
import { Platform } from 'react-native';

type Props = {};

export default class App extends Component<Props> {

  state = {
    versionCode: ''
  }

  constructor(props: Props) {
    super(props)
    this.initialize()
    this.getVersionCode()
  }

  async getVersionCode() {
    // Get the version code of ComPDFKit SDK
    var version = await ComPDFKit.getVersionCode()
    this.setState({
      versionCode: version
    })
  }

  async initialize() {
    // use license file
    var result = await ComPDFKit.initWithPath(Platform.OS == "android" ? "assets://license_key_rn.xml" : "license_key_rn.xml")
    console.log("ComPDFKitRN", "init_:", result)
  }

  /**
     * Open the sample document embedded in Android or iOS project.
     */
  openSample() {
    var samplePDF: string = Platform.OS == 'android' ? 'file:///android_asset/PDF_Document.pdf' : 'PDF_Document.pdf'
    // We provide default UI and PDF property related configurations here, you can modify configuration options according to your needs.
    var config = ComPDFKit.getDefaultConfig({

    })
    ComPDFKit.openDocument(samplePDF, '', config)
  }

  samplePDF = Platform.OS === 'android'
  ? 'file:///android_asset/PDF_Document.pdf'
  : 'PDF_Document.pdf';

  const onPageChanged = (pageIndex : number) =>{
    // console.log('ComPDFKitRN --- onPageChanged:', pageIndex);
  }

  const saveDocument = () => {
    console.log('ComPDFKitRN saveDocument');
  }

  render() {
    return (
      <SafeAreaView style={{ flex: 1 }}>
        <CPDFReaderView
          document={this.samplePDF}
          onPageChanged={onPageChanged}
          saveDocument={saveDocument}
          configuration={ComPDFKit.getDefaultConfig({})}
          style={{ flex: 1 }}
          />
      </SafeAreaView>
    );
  }
}
  • (Android) For local storage file path:
document = '/storage/emulated/0/Download/PDF_document.pdf'
  • (Android) For content Uri:
document = 'content://...'
  • (Android) For assets path:
document = "file:///android_asset/..."
  • (iOS) For app bundle file path:
document = "document.pdf"
  • (iOS) for URL path:
document = "file://xxxx/document.pdf"

Configuration

When rendering a PDF view using the ComPDFKit.openDocument method or the CPDFReaderView UI component , you have the flexibility to enable or disable certain features or adjust default attribute values for PDF annotations, forms, and more through the CPDFConfiguration settings.

For your convenience, you can obtain default attribute values by using the ComPDFKit.getDefaultConfig({}) method.

The following example demonstrates the configuration settings for some aspects. For more detailed configuration options, refer to CONFIGURATION for further information.

  1. Set the initial display mode and the list of available modes. The following code shows enabling only the viewer mode and annotations mode:
import { ComPDFKit, CPDFViewMode } from '@compdfkit_pdf_sdk/react_native';

var config = ComPDFKit.getDefaultConfig({
  modeConfig:{
    initialViewMode: CPDFViewMode.VIEWER,
    availableViewModes: [
      CPDFViewMode.VIEWER,
      CPDFViewMode.ANNOTATIONS
    ]
  }
})

// Use in Modal View
ComPDFKit.openDocument(samplePDF, '', config)

// Use in UI components
<CPDFReaderView
    document={this.samplePDF}
    configuration={config}
    style={{ flex: 1 }}
/>
  1. Set the list of enabled annotation types and default annotation attribute values. For example, enable only highlight annotations and set the color and transparency for highlight annotations:
import { ComPDFKit, CPDFAnnotationType, CPDFConfigTool } from '@compdfkit_pdf_sdk/react_native';

var config = ComPDFKit.getDefaultConfig({
  annotationsConfig: {
    availableType: [
      CPDFAnnotationType.NOTE
    ],
    availableTools: [
      CPDFConfigTool.SETTING,
      CPDFConfigTool.UNDO,
      CPDFConfigTool.REDO,
    ],
    initAttribute: {
      note: {
        color: '#1460F3',
        alpha: 255
      }
    }
  }
})

// Use in Modal View
ComPDFKit.openDocument(samplePDF, '', config)

// Use in UI components
<CPDFReaderView
    document={this.samplePDF}
    configuration={config}
    style={{ flex: 1 }}
/>
  1. Set the display mode and page flipping direction:
import { ComPDFKit, CPDFDisplayMode } from '@compdfkit_pdf_sdk/react_native';

var config = ComPDFKit.getDefaultConfig({
  readerViewConfig: {
    displayMode: CPDFDisplayMode.DOUBLE_PAGE,
    verticalMode: false
  }
})
// Use in Modal View
ComPDFKit.openDocument(samplePDF, '', config)

// Use in UI components
<CPDFReaderView
    document={this.samplePDF}
    configuration={config}
    style={{ flex: 1 }}
/>

API

APIs are available on the API

Support

ComPDFKit has a professional R&D team that produces comprehensive technical documentation and guides to help developers. Also, you can get an immediate response when reporting your problems to our support team.

  • For detailed information, please visit our Guides page.
  • Stay updated with the latest improvements through our Changelog.
  • For technical assistance, please reach out to our Technical Support.
  • To get more details and an accurate quote, please contact our Sales Team.

Thanks for reading The ComPDF Team

changelog

Newest Release

2.4.7 - 12 Sep. 2025

New Features

  1. Added the features support for ComPDFKit PDF SDK for iOS V2.4.7.
  2. Added the features support for ComPDFKit PDF SDK for Android V2.4.7.
  3. Automatically hide the quick scroll bar when the document contains only one page.
  4. Fixed an OOM crash issue caused by importing fonts on the Android platform.
  5. Fixed a display issue with circle annotations when opacity was set to 0 on the Android platform.
  6. Fixed a potential crash when modifying properties of circle and line annotations on the Android platform.
  7. Fixed an issue where some documents failed to correctly trigger callbacks for the first or last page.

Previous Release

2.4.6 - 29 Aug. 2025

  1. Updated iOS ComPDFKit PDF SDK to version 2.4.6.
  2. Updated Android ComPDFKit PDF SDK to version 2.4.6.
  3. Added compatibility for Android 15 and Android 16.
  4. Optimized page layout and zoom logic for an improved reading experience.
  5. Added pinch-to-zoom and page dragging while drawing annotations.
  6. Added support for filling out forms in annotation mode on Android.
  7. Introduced a new API for text search.
  8. Optimized the bottom toolbar UI in signature mode on iOS.
  9. Added JSON configuration to enable/disable error prompts and adjusted the display logic for scan document prompts on iOS.
  10. Added JSON configuration to enable/disable Ink drawing drag and mode-switch buttons.
  11. Unified setting of background color of blank area in theme.
  12. Added API for setting component background color.
  13. Removed the dependency on the prop-types library.
  14. Fixed a crash caused by entering Emoji characters on Android.
  15. Resolved crashes when verifying digital signatures in certain documents on Android.
  16. Fixed an issue where adding digital signatures failed in some documents on Android.
  17. Fixed an issue where pages always aligned to the left after setting horizontal margins on Android.
  18. Fixed page jumping issues in vertical scrolling mode when horizontal margins were set on Android.
  19. Fixed an issue where FreeText annotations did not fully display after being saved on Android.
  20. Resolved a crash caused by InitOutFont during SDK initialization on Android.
  21. Fixed an issue where save() did not save ongoing Ink and Pencil annotations on iOS.
  22. Fixed an issue where the top text was not vertically centered on iOS.
  23. Fixed flickering when opening a document multiple times on iOS.
  24. Fixed lagging when scrolling in content editing mode on iOS.

2.4.4 - 27 Jun. 2025

  1. Fixed the “Super expression must either be null or a function” error caused by incorrect class inheritance when using the Hermes engine.

2.4.3 - 26 Jun. 2025

  1. Added the features support for ComPDFKit PDF SDK for iOS V2.4.3.
  2. Added the features support for ComPDFKit PDF SDK for Android V2.4.3.
  3. Fixed a crash issue when exporting annotation files in certain documents
  4. Fixed an issue where selecting an annotation would unexpectedly switch the current drawing annotation type
  5. Fixed an issue where deleted text content in some documents was not saved properly
  6. Optimized the flickering issue when jumping to a specific page
  7. Improved the page navigation logic during annotation undo and redo operations

2.4.1 - 19 Jun. 2025

  1. Added the features support for ComPDFKit PDF SDK for iOS V2.4.1.
  2. Added the features support for ComPDFKit PDF SDK for Android V2.4.1.
  3. Added API to switch between different annotation types in annotation mode.
  4. Added Undo and Redo APIs for annotation actions.
  5. Added configuration option to hide the bottom annotation toolbar in annotation mode.
  6. Added support for context menu configuration.
  7. Added callback for tapping on the PDF page area.
  8. Adapted Android platform to support 16KB page sizes.
  9. Fixed an issue where some APIs became unresponsive, causing blocking behavior.
  10. Fixed an issue where the read-only (readOnly) setting had no effect on Android.
  11. Fixed a bug where the page.removeAnnotation() API could not delete annotations on Android.
  12. Fixed an issue where getReadBackgroundColor() returned the wrong color on iOS.

2.4.1-beta.1 - 03 Jun. 2025

  1. Fixed a build failure caused by incorrect package name com.compdfkitpdf generated during auto-linking.

2.4.0 - 15 May. 2025

  1. Added the features support for ComPDFKit PDF SDK for iOS V2.4.0.
  2. Added the features support for ComPDFKit PDF SDK for Android V2.4.0.
  3. Added configuration options for signature methods in signature form fields on Android.
  4. Added a document save reminder when exiting the interface on Android.
  5. Added functionality to erase existing Ink annotations on Android.
  6. Added APIs to delete annotations and form fields.
  7. Added an API to insert blank pages.
  8. Enhanced annotation property data.
  9. Enhanced form field property data.
  10. Fixed OOM crash issues on some devices during SDK initialization.
  11. Fixed an issue where signature appearance was not correctly displayed after digital signing.
  12. Fixed an issue where images failed to display after adding a watermark to certain documents.
  13. Fixed an issue that prevented inserting PNG images when inserting pages.
  14. Fixed incorrect handling of ActionType_GoToR and ActionType_Launch in hyperlink annotations.
  15. Fixed an issue where long input in electronic signatures within ComPDFKit_Tools caused incomplete display after saving.
  16. Fixed blurry display issue after zooming in on text annotations.
  17. Fixed jump behavior of CPDFReaderView.setScale()scaling method.
  18. Fixed a font inconsistency issue during content editing when adding text to already selected text with an existing device font.

2.3.0 - 21 Mar. 2025

  1. Added the features support for ComPDFKit PDF SDK for iOS iOS V2.3.0.
  2. Added the features support for ComPDFKit PDF SDK for Android Android V2.3.0.
  3. Added import/export form data API, supporting XFDF format files.
  4. Added the ability to create text input fields and insert images by clicking on a page area in content editing mode.
  5. Added navigation system print API.
  6. Added import PDF document API.
  7. Added split PDF document API.
  8. Added fill form content API.
  9. Added saveAs API.
  10. Added API to retrieve all annotations and form data on a page.
  11. Added document flattening API.
  12. Fixed a crash issue when editing or deleting text in certain documents.
  13. Fixed the border display issue after completing a free text annotation.
  14. Fixed an issue where the LaBan Key input method could not delete the last character while editing text.
  15. Fixed text garbling issues in content editing mode.
  16. Fixed an issue where form field content was not displayed in some documents.
  17. Fixed the issue that the zoomed-in page area did not follow the zooming when jumping to draw a rectangular area.
  18. Fixed the issue of Chinese garbled characters in the form name.
  19. Fixed the issue where the prompt did not appear for scanned PDF documents on iOS.

2.3.0-beta.1 - 28 Feb. 2025

  • Added import/export interface for form data in XFDF format files.
  • Added the ability to create text input boxes and insert images by clicking on the page area in content editing mode.
  • Added a system print API for navigation.
  • Fixed issue where editing or deleting text in some documents caused crashes.
  • Fixed issue with the border appearing after completing FreeText annotation.
  • Fixed issue where the LaBan Key input method deletes the last character when editing text.
  • Fixed the issue of text garbling in content editing mode.

2.2.2 - 19 Feb. 2025

  • Added the features support for ComPDFKit PDF SDK for iOS iOS V2.2.2.
  • Added the features support for ComPDFKit PDF SDK for Android Android V2.2.2.
  • Added the ability to save a watermark to the current PDF when adding it.
  • Fixed the inaccurate judgment issue in the hasChange() method.
  • Fixed an issue where some document text fields in forms were not displaying content.
  • Fixed an issue on the Android platform where Ink annotations became smaller after drawing.
  • Fixed an issue on the Android platform where the pen size shrank when drawing Ink annotations after zooming in on a page.
  • Fixed an input issue with the LaBan Key input method on the Android platform.
  • Fixed a potential crash issue on the Android platform when enabling the rotate function.
  • Fixed a crash issue on the Android platform when importing XFDF annotations.

2.2.1 - 21 Jan. 2025

  • Added the features support for ComPDFKit PDF SDK for iOS iOS V2.2.1.
  • Added the features support for ComPDFKit PDF SDK for Android Android V2.2.1.
  • Added API for importing fonts.
  • Added API for security settings.
  • Added view-related APIs, including opening thumbnail lists, preview settings, watermark editing, and security settings.
  • Fixed the issue with the CPDFReaderView UI component on Android, which caused the Activity theme to be abnormal.
  • Fixed an issue where certain documents could crash when importing XFDF annotations.
  • Fixed an issue on iOS where the author information for Ink annotations was not displayed.
  • Fixed a crash in iOS 18 when editing content in the context menu.
  • Fixed a crash on certain Android devices when initializing the SDK.
  • Fixed a crash on Android related to screenshot functionality.
  • Optimize the screenshot function of the Android platform to improve the quality of image capture
  • Fixed an issue on Android with the LaBan Key input method.
  • Fixed an issue on Android where the modified date was not updated when saving a modified document.
  • Fixed a crash on Android related to the undo operation in content editing.
  • Fixed an issue on Android where form background color was transparent when highlighting forms was not enabled.
  • Fixed an issue on Android where annotation text would display incorrectly when editing text in highlighted comment areas.
  • Fixed an issue on Android where cloud comment borders were displayed incorrectly in graphic annotations. For detailed information about the new interfaces, please refer to CPDFReaderView.tsx and CPDFDocument.tsx.

2.2.0 - 13 Dec. 2024

  • Added features support for ComPDFKit PDF SDK for Android V2.2.0.
  • Added features support for ComPDFKit PDF SDK for iOS V2.2.0.
  • Added import and export annotation interfaces.
  • Added delete all annotations interface.
  • Added get page number interface and page number listener callback.
  • Added save document callback.
  • Optimized document saving logic on iOS platform.

2.1.3-2 - 26 Sep 2024

  • Added the features support for ComPDFKit PDF SDK for Android V2.1.3.
  • Fixed crash issue when opening certain documents.
  • Fixed crash issue when adding mark annotations to some documents.
  • Fixed potential crash during SDK initialization.
  • Fixed incomplete display of underline annotations.
  • Fixed abnormal annotation display after rotating the page.
  • Fixed crash when releasing watermarks.
  • Fixed memory leak in the property window of the ComPDFKit_Tools module.

2.1.3-1 - 25 Sep 2024

  • Added the features support for ComPDFKit PDF SDK for iOS V2.1.3.
  • iOS annotation toolbar image button adaptation for iPad.
  • RN iOS sandbox structure modification.

2.1.2 - 01 Sep 2024

  • Added CPDFReaderView UI component.
  • Optimize document opening speed.

2.1.1 - 12 Aug 2024

  • Added the features support for ComPDFKit PDF SDK for iOS V2.1.1.
  • Added the features support for ComPDFKit PDF SDK for Android V2.1.1.
  • Optimized the logic for selecting text by long press.
  • Fixed low text contrast issue in dark mode for some documents.
  • Fixed crash issues with some documents.

2.1.0 - 29 July 2024

  • Added the features support for ComPDFKit PDF SDK for iOS V2.1.0.
  • Added the features support for ComPDFKit PDF SDK for Android V2.1.0.
  • Added annotation reply functionality.
  • Optimized text aggregation logic for content editing.
  • Added font subsetting.
  • Added screenshot feature.
  • Android platform adaptation for Laban Key Keyboard.
  • Fixed an issue with the Ink annotation color display on Android.

2.0.1 - 13 May 2024

  • Provide dependency methods from GitHub and npm.
  • Added the features support for ComPDFKit PDF SDK for iOS V2.0.1.
  • Added the features support for ComPDFKit PDF SDK for Android V2.0.1.
  • Fix the issue of continuous memory growth.

2.0.1-beta.2 - 13 May 2024

  • Adjust some document description errors.

2.0.1-beta.1 - 10 May 2024

  • Provide dependency methods from GitHub and npm.
  • Added the features support for ComPDFKit PDF SDK for iOS V2.0.1.
  • Added the features support for ComPDFKit PDF SDK for Android V2.0.1.
  • Fix the issue of continuous memory growth.