No Description

C-yangliuhua c4d8af642c ComPDFKit(RN) - profile 文件修改 11 months ago
.bundle 93b6744b08 PDFViewerRN(ios/Android) - 项目示例 1 year ago
.vscode 03545dfb11 ComPDFKit(React-Native) - iOS SDK 1.11.0 的更新 11 months ago
Image 78e4c628c3 compdfkit(rn) 1.0.0_release 1 year ago
__tests__ 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
android 56379ecca7 compdfkit(rn) - android 1.11.0 maven依赖 11 months ago
ios c4d8af642c ComPDFKit(RN) - profile 文件修改 11 months ago
.eslintrc.js 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
.gitignore 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
.prettierrc.js 93b6744b08 PDFViewerRN(ios/Android) - 项目示例 1 year ago
.watchmanconfig 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
App.tsx 6bba8abfeb compdfkit(rn) - 优化 11 months ago
Gemfile 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
Gemfile.lock 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
README.md 78e4c628c3 compdfkit(rn) 1.0.0_release 1 year ago
app.json 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
babel.config.js 93b6744b08 PDFViewerRN(ios/Android) - 项目示例 1 year ago
index.js 03545dfb11 ComPDFKit(React-Native) - iOS SDK 1.11.0 的更新 11 months ago
jest.config.js 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
metro.config.js 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
package.json 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
tsconfig.json 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago
yarn.lock 8d81ab00d3 compdfkit(rn) - 1.ComPDFKit SDK 升级至1.9.1 2.rn升级至0.72.5 1 year ago

README.md

1 Overview

ComPDFKit for React Native is a comprehensive SDK that allows you to quickly add PDF fuctions to any React Native application, such as viewer, annotations, editing PDFs, forms and signatures.

More information can be found at https://www.compdf.com/

1.1 ComPDFKit PDF SDK

ComPDFKit PDF SDK consists of two elements as shown in the following picture.

The two elements for ComPDFKit PDF SDK:

  • PDF Core API

The Core API can be used independently for document rendering, analysis, text extraction, text search, form filling, password security, annotation creation and manipulation, and much more.

  • PDF View

The PDF View is a utility class that provides the functionality for developers to interact with rendering PDF documents per their requirements. The View Control provides fast and high-quality rendering, zooming, scrolling, and page navigation features. The View Control is derived from platform-related viewer classes (e.g. UIView on iOS) and allows for extension to accommodate specific user needs.

1.2 Key Features

Viewer component offers:

  • Standard page display modes, including Scrolling, Double Page, Crop Mode, and Cover Mode.
  • Navigation with thumbnails, outlines, and bookmarks.
  • Text search & selection.
  • Zoom in and out & Fit-page.
  • Switch between different themes, including Dark Mode, Sepia Mode, Reseda Mode, and Custom Color Mode.
  • Text reflow.

Annotations component offers:

  • Create, edit, and remove annotations, including Note, Link, Free Text, Line, Square, Circle, Highlight, Underline, Squiggly, Strikeout, Stamp, Ink, and Sound.
  • Support for annotation appearances.
  • Import and export annotations to/from XFDF.
  • Support for annotation flattening.
  • Predefine annotations.

Forms component offers:

  • Create, edit and remove form fields, including Push Button, Check Box, Radio Button, Text Field, Combo Box, List Box, and Signature.
  • Fill PDF Forms.
  • Support for PDF form flattening.

Document Editor component offers:

  • PDF manipulation, including Split pages, Extract pages, and Merge pages.
  • Page edit, including Delete pages, Insert pages, Crop pages, Move pages, Rotate pages, Replace pages, and Exchange pages.
  • Document information setting.
  • Extract images.

Content Editor component offers:

  • Programmatically add and remove text in PDFs and make it possible to edit PDFs like Word. Allow selecting text to copy, resize, change colors, text alignment, and the position of text boxes.
  • Undo or redo any change.

1.3 License

ComPDFKit PDF SDK is a commercial SDK, which requires a license to grant developer permission to release their apps. Each license is only valid for one bundle ID or applicationId in development mode. Other flexible licensing options are also supported, please contact our marketing team to know more. However, any documents, sample code, or source code distribution from the released package of ComPDFKit to any third party is prohibited.

To initialize ComPDFKit using a license key, call either of the following before using any other ComPDFKit APIs or features:

To set the license key for iOS, use:

// Set your license key here. ComPDFKit is commercial software.
  // Each ComPDFKit license is bound to a specific app bundle id.
  // com.compdfkit.pdfviewer
    
 [CPDFKit setLicenseKey:@"YOUR_LICENSE_KEY_GOES_HERE"
                    secret:@"YOUR_LICENSE_SECRET_GOES_HERE"];

To set the license key for Android , use:

<!-- Add this license in the AndroidManifest.xml of the main module --/>
<meta-data
    android:name="compdfkit_key"
    android:value="{your ComPDFKit key}" />
<meta-data
    android:name="compdfkit_secret"
    android:value="{your ComPDFKit secret}" />

2 Get Started

It's easy to embed ComPDFKit into React Native applications with a few lines of code. Let's take a few minutes to get started.

The following sections describe the optimal systems and environments to support, as well as quick integration steps.

2.1 Requirements

Android

Please install the following required packages:

Operating Environment Requirements:

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

iOS

Please install the following required packages:

Operating Environment Requirements:

  • ComPDFKit SDK 1.9.0 or higher.
  • React Native dependency to version 3.0.0 or higher.
  • iOS 10.0 or higher.

2.2 Getting Started

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
  1. Create the React Native project by running the following command:
   react-native init compdfkit_rn
  1. In the terminal app, change the location of the current working directory inside the newly created project:
   cd compdfkit_rn
  1. Add the ComPDFKit library and import the presented PDF document.

For iOS

Open your project’s Podfile in a text editor:

open ios/Podfile

Update the platform to iOS 10 and add the ComPDFKit Podspec:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

- platform :ios, '10.0'
+ platform :ios, '11.0'
install! 'cocoapods', :deterministic_uuids => false

target 'PDFView_RN' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'PDFView_RNTests' do
    inherit! :complete
    # Pods for testing
  end

+  pod 'ComPDFKit_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/latest.podspec'
+  pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/latest.podspec'

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

Go to the compdfkit_rn/ios folder and run the pod install command:

pod install

Open your project’s Workspace in Xcode:

open ios/PDFView_RN.xcworkspace	

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

Import resource file,CPDFViewController view controller that contains ready-to-use UI module implementations.

1.2

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 "developer_guide_ios.pdf" as an example.

To protect user privacy, before accessing the sensitive privacy data, you need to find the "Info" configuration in your iOS 10.0 or higher iOS project and configure the relevant privacy terms as shown in the following picture.

<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>

For Android

Open the android/build.gradle file located in the project root directory and add the mavenCentral repository:

repositories {
    google()
+   mavenCentral()
}

Open the app’s Gradle build file, android/app/build.gradle:

open android/app/build.gradle

Modify the minimum SDK version, All this is done inside the android section:

 android {
     defaultConfig {
-        minSdkVersion rootProject.ext.minSdkVersion
+        minSdkVersion 21
         ...
     }
 }

Add ComPDFKit SDK inside the dependencies section:

dependencies {
    ...
+    implementation 'com.compdf:compdfkit:1.9.1'
+    implementation 'com.compdf:compdfkit-ui:1.9.1'
+    implementation 'com.compdf:compdfkit-tools:1.9.1'
+     implementation 'pub.devrel:easypermissions:3.0.0'
}

open android/app/src/main/AndroidManifest.xml , addComPDFKit License and Storage Permission

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.compdfkit.flutter.example">
    
    <!-- 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"/>

    <application
        ...>
        ...
        <!-- Please replace it with your ComPDFKit license -->
+        <meta-data
+            android:name="compdfkit_key"
+            android:value="{your license key}" />
+        <meta-data
+            android:name="compdfkit_secret"
+            android:value="{your license secret}" />
				...
    </application>
</manifest>

Enable viewBinding in the android node setting of app/build.gradle

android {
		...
    buildFeatures {
        viewBinding = true
    }
}

Copy the pdf folder and res/layout code from the sample project Android project to your project

1-5

Open the MainApplication file and fill in the following code in the getPackages() method

@Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
+  packages.add(new PDFReactPackage());
  return packages;
}

Add PDFActivity in AndroidManifest.xml file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.projectname">
  <application
    ...>
    ...
+    <activity
+              android:name=".pdf.PDFActivity"
+              android:configChanges="keyboardHidden|orientation|screenSize"
+              android:windowSoftInputMode="adjustPan"
+              android:exported="true"/>

    </activity>
  </application>
</manifest>

Copy the sample pdf file to the assets directory

1-6

  1. Open your App.js file:
open App.js
  1. Replace the entire contents of App.js with the following code snippet:
/**
 * Sample React Native App
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button,
  NativeModules
} from 'react-native';

var nativeModule = NativeModules.OpenNativeModule;
// var analyticsModule = NativeModules.UMAnalyticsModule;


const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <Button
          title={'Jump to the native page'}
          onPress={() => {
            this.jumpToNativeView();
          }}
        />
      </View>
    );
  }
  
  jumpToNativeView() {
        NativeModules.OpenPDFModule.openPDF()
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
  1. We have provided two quick ways to open PDFs:
  • Open the default document directly
RCT_EXPORT_METHOD(openPDF);
  • Open the document in the specified path
RCT_EXPORT_METHOD(openPDFByPath:(nonnull NSString *)filePath)

The app is now ready to launch! Go back to the terminal.

//Run on Android devices
npx react-native run-android

//Run on iOS devices
npx react-native run-ios

3 Support

3.1 Reporting Problems

Thank you for your interest in ComPDFKit PDF SDK, the only easy-to-use but powerful development solution to integrate high quality PDF rendering capabilities to your applications. If you encounter any technical questions or bug issues when using ComPDFKit PDF SDK for React Native, please submit the problem report to the ComPDFKit team. More information as follows would help us to solve your problem:

  • ComPDFKit PDF SDK product and version.
  • Your operating system and IDE version.
  • Detailed descriptions of the problem.
  • Any other related information, such as an error screenshot.

3.2 Contact Information

Home Link:

https://www.compdf.com

Support & General Contact:

Email: support@compdf.com

Thanks, The ComPDFKit Team