Jelajahi Sumber

compdfkit(rn) - 完善cpdfconfiguration文档内容,ios接入compdfkit

liuxiaolong 10 bulan lalu
induk
melakukan
94ea1fc658

+ 200 - 0
API.md

@@ -0,0 +1,200 @@
+# ComPDFKit React Native API
+
+## TypeScript
+
+ComPDFKit React Native supports TypeScript. Types used in this document will be described using TypeScript types. Type information is automatically provided when encoding, and the exact type aliases and constants used in our custom types can be found in the [CPDFConfiguration](./src/configuration/CPDFConfiguration.ts) and [CPDFOptions](./src/configuration/CPDFOptions.ts) source folders.
+
+
+
+## ComPDFKit
+
+ComPDFKit contains static methods for global library initialization, configuration, and utility methods.
+
+
+
+### init_
+
+Initialize the ComPDFKit SDK offline using your ComPDFKit commercial license key. Please contact our sales to obtain a trial license.
+
+Parameters:
+
+| Name    | Type   | Description                |
+| ------- | ------ | -------------------------- |
+| license | String | Your ComPDFKit license key |
+
+Returns a Promise.
+
+| Name   | Type    | Description                                                  |
+| ------ | ------- | ------------------------------------------------------------ |
+| result | boolean | Returns ```true``` if initialization is successful, otherwise returns ```false```. |
+
+```tsx
+ComPDFKit.init_('your compdfkit license')
+```
+
+
+
+### initialize
+
+Use your ComPDFKit commercial license key to initialize the ComPDFKit SDK using online authentication. Please contact our sales to obtain a trial license.
+
+Parameters:
+
+| Name                 | Type   | Description                                                 |
+| -------------------- | ------ | ----------------------------------------------------------- |
+| androidOnlineLicense | string | Your ComPDFKit for React Native Android online license key. |
+| iosOnlineLicense     | string | Your ComPDFKit for React Native iOS online license key.     |
+
+Returns a Promise.
+
+| Name   | Type    | Description                                                  |
+| ------ | ------- | ------------------------------------------------------------ |
+| result | boolean | Returns ```true``` if initialization is successful, otherwise returns ```false```. |
+
+```tsx
+ComPDFKit.initialize('android online license', 'ios online license')
+```
+
+
+
+### getVersionCode
+
+Get the version number of the ComPDFKit SDK.
+
+For example: '2.0.1'
+
+Returns a Promise.
+
+| Name        | Type   | Description                              |
+| ----------- | ------ | ---------------------------------------- |
+| versionCode | String | the version number of the ComPDFKit SDK. |
+
+```tsx
+ComPDFKit.getVersionCode().then((versionCode : string) => {
+  console.log('ComPDFKit SDK Version:', versionCode)
+})
+```
+
+
+
+### getSDKBuildTag
+
+Get the build tag of the ComPDFKit PDF SDK.
+
+For example: "build_beta_2.0.0_42db96987_202404081007"
+
+Returns a Promise.
+
+| Name     | Type   | Description                             |
+| -------- | ------ | --------------------------------------- |
+| buildTag | String | the build tag of the ComPDFKit PDF SDK. |
+
+```tsx
+ComPDFKit.getSDKBuildTag().then((buildTag : string) => {
+  console.log('ComPDFKit Build Tag:', buildTag)
+})
+```
+
+
+
+### openDocument
+
+Used to present a PDF document.
+
+Parameters:
+
+| Name          | Type   | Description                                                  |
+| ------------- | ------ | ------------------------------------------------------------ |
+| document      | string | The path to the PDF document to be presented.                |
+| password      | string | PDF document password.                                       |
+| configuration | string | Configuration objects to customize the appearance and behavior of ComPDFKit. |
+
+* (Android) For local storage file path:
+```tsx
+document = 'file:///storage/emulated/0/Download/sample.pdf'
+ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))
+```
+
+* (Android) For content Uri: 
+
+```tsx
+document = 'content://...'
+ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))
+```
+
+* (Android) For assets path:
+
+```tsx
+document = "file:///android_asset/..."
+ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))
+```
+
+* (iOS) For app bundle file path:
+
+```tsx
+document = 'pdf_document.pdf'
+ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))
+```
+
+
+
+### getDefaultConfig
+
+When you use the `ComPDFKit.openDocument` method to present a PDF file, you need to pass configuration parameters to customize the UI features and PDF view properties. `ComPDFKit` provides default configuration parameters through `ComPDFKit.getDefaultConfig`. You can retrieve them using the following example:
+
+```tsx
+ComPDFKit.getDefaultConfig({})
+```
+
+You can modify certain parameters to meet your requirements. Here are some usage examples:
+
+1. Setting the initial display mode and available mode list. The following code is an example that enables only the viewer mode and annotation mode:
+
+```tsx
+ComPDFKit.getDefaultConfig({
+  modeConfig: {
+    initialViewMode: CPDFViewMode.VIEWER,
+    availableViewModes: [
+      CPDFViewMode.VIEWER,
+      CPDFViewMode.ANNOTATIONS
+    ]
+  }
+})
+```
+
+2. Setting the enabled annotation types and the default annotation attribute values list. For example, enabling only note annotations and setting the color and transparency of note annotations:
+
+```tsx
+ComPDFKit.getDefaultConfig({
+  annotationsConfig:{
+    availableType:[
+      CPDFAnnotationType.NOTE
+    ],
+    availableTools:[
+      CPDFConfigTool.SETTING,
+      CPDFConfigTool.UNDO,
+      CPDFConfigTool.REDO
+    ],
+    initAttribute:{
+      note:{
+        color: '#1460F3',
+        alpha: 255
+      }
+    }
+  }
+})
+```
+
+3.Setting the display mode and page turning direction:
+
+```tsx
+ComPDFKit.getDefaultConfig({
+  readerViewConfig:{
+    displayMode: CPDFDisplayMode.DOUBLE_PAGE,
+    verticalMode: false
+  }
+})
+```
+
+For more configuration parameter descriptions, please see [CPDFCONFIGURATION.md](./CONFIGURATION.md).
+

+ 7 - 0
CHANGELOG.md

@@ -0,0 +1,7 @@
+## Newest Release
+
+### 2.0.1-beta.1 - 17 May 2024
+
+
+
+## Previous Release

File diff ditekan karena terlalu besar
+ 1022 - 0
CONFIGURATION.md


+ 5 - 3
example/App.tsx

@@ -15,7 +15,8 @@ import {
   View,
   TouchableOpacity
 } from 'react-native';
-import { ComPDFKit } from 'react-native-compdfkit-pdf';
+import { ComPDFKit, CPDFViewMode } from 'react-native-compdfkit-pdf';
+import { CPDFAnnotationType, CPDFConfigTool, CPDFDisplayMode } from '../src/configuration/CPDFOptions';
 
 
 type Props = {
@@ -29,13 +30,13 @@ export default class App extends Component<Props> {
   constructor(props: Props) {
     super(props)
 
-    ComPDFKit.initialize('vxwRHJC9RDKK0He2jTpepBkrolOnPQt7bxjfIiqqcJc=', 'vTXxqCm2rutpV67wRy+UnBSJzDBwG0/DLjiLL61zxxc=')
+    // ComPDFKit.initialize('vxwRHJC9RDKK0He2jTpepBkrolOnPQt7bxjfIiqqcJc=', 'vTXxqCm2rutpV67wRy+UnBSJzDBwG0/DLjiLL61zxxc=')
 
     this.getVersionCode()
   }
 
   async getVersionCode() {
-    var version = await ComPDFKit.getVersionCode()
+    var version = await ComPDFKit.getSDKBuildTag()
     this.setState({
       versionCode: version
     })
@@ -68,6 +69,7 @@ export default class App extends Component<Props> {
                 type: [DocumentPicker.types.pdf]
               });
               pickerResult.then(res => {
+                console.log('path:' , res[0]?.uri)
                 ComPDFKit.openDocument(res[0]?.uri as string, '', ComPDFKit.getDefaultConfig({}))
               })
             } catch (err) {

+ 2 - 1
example/assets/configuration.json

@@ -252,6 +252,7 @@
     "enableSliderBar": true,
     "enablePageIndicator": true,
     "pageSpacing": 10,
-    "pageScale": 1.0
+    "pageScale": 1.0,
+    "pageSameWidth":true
   }
 }

+ 4 - 2
example/ios/CompdfkitPdfExample.xcodeproj/project.pbxproj

@@ -484,6 +484,7 @@
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				CLANG_ENABLE_MODULES = YES;
 				CURRENT_PROJECT_VERSION = 1;
+				DEVELOPMENT_TEAM = 59AC9PMNH2;
 				ENABLE_BITCODE = NO;
 				INFOPLIST_FILE = CompdfkitPdfExample/Info.plist;
 				LD_RUNPATH_SEARCH_PATHS = (
@@ -496,7 +497,7 @@
 					"-ObjC",
 					"-lc++",
 				);
-				PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
+				PRODUCT_BUNDLE_IDENTIFIER = com.compdfkit.reactnative.example;
 				PRODUCT_NAME = CompdfkitPdfExample;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_VERSION = 5.0;
@@ -511,6 +512,7 @@
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				CLANG_ENABLE_MODULES = YES;
 				CURRENT_PROJECT_VERSION = 1;
+				DEVELOPMENT_TEAM = 59AC9PMNH2;
 				INFOPLIST_FILE = CompdfkitPdfExample/Info.plist;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
@@ -522,7 +524,7 @@
 					"-ObjC",
 					"-lc++",
 				);
-				PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
+				PRODUCT_BUNDLE_IDENTIFIER = com.compdfkit.reactnative.example;
 				PRODUCT_NAME = CompdfkitPdfExample;
 				SWIFT_VERSION = 5.0;
 				VERSIONING_SYSTEM = "apple-generic";

+ 1 - 1
example/ios/CompdfkitPdfExample/Info.plist

@@ -17,7 +17,7 @@
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-	<string>1.13.1</string>
+	<string>2.0.1-beta.1</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>

+ 2 - 2
example/ios/Podfile

@@ -27,8 +27,8 @@ end
 
 target 'CompdfkitPdfExample' do
   config = use_native_modules!
-  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/1.12.0.podspec'
-  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/1.12.0.podspec'
+  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.0.1.podspec'
+  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.0.1.podspec'
 
 
   use_react_native!(

+ 6 - 1
ios/CompdfkitPdf.mm

@@ -1,11 +1,16 @@
 #import <React/RCTBridgeModule.h>
 
-@interface RCT_EXTERN_MODULE(CompdfkitPdf, NSObject)
+@interface RCT_EXTERN_MODULE(ComPDFKit, NSObject)
 
 RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
                  withResolver:(RCTPromiseResolveBlock)resolve
                  withRejecter:(RCTPromiseRejectBlock)reject)
 
+RCT_EXTERN_METHOD(getSDKBuildTag:
+                 withResolver:(RCTPromiseResolveBlock)resolve
+                 withRejecter:(RCTPromiseRejectBlock)reject)
+
+
 + (BOOL)requiresMainQueueSetup
 {
   return NO;

+ 20 - 0
ios/ComPDFKit.swift

@@ -0,0 +1,20 @@
+import ComPDFKit
+import ComPDFKit_Tools
+
+@objc(ComPDFKit)
+class ComPDFKit: NSObject {
+
+  @objc(multiply:withB:withResolver:withRejecter:)
+  func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
+    resolve(a*b)
+  }
+    
+
+    @objc(getSDKBuildTag:withResolver:withRejecter:)
+      func getSDKBuildTag(_ dummy: Any, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
+        // Implement your getSDKBuildTag logic here
+        // For example:
+        let sdkBuildTag = "ios test sdkBuildTag"
+        resolve(sdkBuildTag)
+      }
+}

+ 0 - 8
ios/CompdfkitPdf.swift

@@ -1,8 +0,0 @@
-@objc(CompdfkitPdf)
-class CompdfkitPdf: NSObject {
-
-  @objc(multiply:withB:withResolver:withRejecter:)
-  func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
-    resolve(a*b)
-  }
-}

+ 2 - 0
react-native-compdfkit-pdf.podspec

@@ -36,6 +36,8 @@ Pod::Spec.new do |s|
     s.dependency "RCTRequired"
     s.dependency "RCTTypeSafety"
     s.dependency "ReactCommon/turbomodule/core"
+    s.dependency "ComPDFKit"
+    s.dependency "ComPDFKit_Tools"
    end
   end    
 end

+ 31 - 11
src/configuration/CPDFConfiguration.ts

@@ -130,8 +130,8 @@ export class CPDFConfiguration {
             },
             /**
              * Ink annotation attribute configuration.
-             * @param {HexColor} [color] HEX color: #1460F3
-             * @param {ColorAlpha} [alpha] Color opacity, value range: 0~255
+             * @param { HexColor } [color] HEX color: #1460F3
+             * @param { ColorAlpha } [alpha] Color opacity, value range: 0~255
              * @param { BorderWidth } [borderWidth] Brush thickness, value range: 1~10
              */
             ink?: {
@@ -347,34 +347,54 @@ export class CPDFConfiguration {
      * PDF View configuration.
      */
     readerViewConfig?: {
+        /**
+         * Sets whether hyperlinks in the PDF document annotations are highlighted.
+         */
         linkHighlight?: boolean,
+        /**
+         * Sets whether form fields in the PDF document are highlighted.
+         */
         formFieldHighlight?: boolean,
+        /**
+         * Display mode of the PDF document, single page, double page, or book mode.
+         * Default: {@link CPDFDisplayMode.SINGLE_PAGE}
+         */
         displayMode?: CPDFDisplayMode,
         /**
-         * PDF翻页是否为连续滚动
+         * Whether PDF page flipping is continuous scrolling.
          */
         continueMode?: boolean,
         /**
-         * 是否为垂直方向滚动
-         * true: 垂直滚动, false: 水平滚动
-         * 默认: true
+         * Whether scrolling is in vertical direction.
+         * `true`: Vertical scrolling, `false`: Horizontal scrolling.
+         * Default: true
          */
         verticalMode?: boolean,
         /**
-         * 裁剪模式
-         * 是否裁剪PDF页面空白区域
-         * 默认:false
+         * Cropping mode.
+         * Whether to crop blank areas of PDF pages.
+         * Default: false
          */
         cropMode?: boolean,
+        /**
+         * Theme color.
+         * Default: {@link CPDFThemes.light}
+         */
         themes?: CPDFThemes,
+        /**
+         * Whether to display the sidebar quick scroll bar.
+         */
         enableSliderBar?: boolean,
+        /**
+         * Whether to display the bottom page indicator.
+         */
         enablePageIndicator?: boolean,
         /**
-         * 每页PDF的间距, 默认10px
+         * Spacing between each page of the PDF, default 10px.
          */
         pageSpacing?: number,
         /**
-         * 页面缩放值, 默认1.0
+         * Page scale value, default 1.0.
          */
         pageScale?: number,
         /**

+ 0 - 2
src/configuration/CPDFOptions.ts

@@ -1,5 +1,3 @@
-
-
 export const CPDFViewMode = {
 
     /**

+ 2 - 3
src/index.tsx

@@ -6,7 +6,6 @@ declare module 'react-native' {
   interface NativeModulesStatic {
     ComPDFKit: {
       getDefaultConfig(overrides : Partial<CPDFConfiguration>) : string;
-      testConfig(configuration: string): () => Promise<string>;
       /**
        * Get the version number of the ComPDFKit SDK.
        * For example : '2.0.0'
@@ -393,13 +392,13 @@ function getDefaultConfig(overrides : Partial<CPDFConfiguration> = {}) : string
   return JSON.stringify(mergeDeep(defaultConfig, overrides), null, 2);
 }
 
-// 辅助函数:深度合并对象
+
 function mergeDeep(defaults: any, overrides: any): any {
   const merged = { ...defaults };
 
   for (const key in overrides) {
       if (Array.isArray(overrides[key]) && Array.isArray(defaults[key])) {
-          merged[key] = [...overrides[key]]; // 使用新数组替换旧数组
+          merged[key] = [...overrides[key]];
       } else if (overrides[key] instanceof Object && key in defaults) {
           merged[key] = mergeDeep(defaults[key], overrides[key]);
       } else {