C-yangliuhua c4d8af642c ComPDFKit(RN) - profile 文件修改 | 11 months ago | |
---|---|---|
.bundle | 1 year ago | |
.vscode | 11 months ago | |
Image | 1 year ago | |
__tests__ | 1 year ago | |
android | 11 months ago | |
ios | 11 months ago | |
.eslintrc.js | 1 year ago | |
.gitignore | 1 year ago | |
.prettierrc.js | 1 year ago | |
.watchmanconfig | 1 year ago | |
App.tsx | 11 months ago | |
Gemfile | 1 year ago | |
Gemfile.lock | 1 year ago | |
README.md | 1 year ago | |
app.json | 1 year ago | |
babel.config.js | 1 year ago | |
index.js | 11 months ago | |
jest.config.js | 1 year ago | |
metro.config.js | 1 year ago | |
package.json | 1 year ago | |
tsconfig.json | 1 year ago | |
yarn.lock | 1 year ago |
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/
ComPDFKit PDF SDK consists of two elements as shown in the following picture.
The two elements for ComPDFKit PDF SDK:
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.
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.
Viewer component offers:
Annotations component offers:
Forms component offers:
Document Editor component offers:
Content Editor component offers:
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}" />
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.
Android
Please install the following required packages:
A development environment for running React Native projects using the React Native CLI (not the Expo CLI)
The Android NDK
An Android Virtual Device or a hardware device
Operating Environment Requirements:
minSdkVersion
of 21
or higher.iOS
Please install the following required packages:
A development environment for running React Native projects using the React Native CLI (not the Expo CLI)
The latest stable version of CocoaPods. Follow the CocoaPods installation guide to install it.
Operating Environment Requirements:
Let's create a simple app that integrates ComPDFKit for React Native.
~/Documents/
directory: cd ~/Documents
react-native init compdfkit_rn
cd compdfkit_rn
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.
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>
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
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
App.js
file:open App.js
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,
},
});
RCT_EXPORT_METHOD(openPDF);
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
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:
Home Link:
Support & General Contact:
Email: support@compdf.com
Thanks, The ComPDFKit Team