Browse Source

compdfkit(rn) - 新增接口

liuxiaolong 10 months ago
parent
commit
b954275fa5

+ 1 - 0
.gitignore

@@ -54,6 +54,7 @@ node_modules/
 npm-debug.log
 yarn-debug.log
 yarn-error.log
+yarn.lock
 
 # BUCK
 buck-out/

+ 1 - 0
.npmignore

@@ -54,6 +54,7 @@ node_modules/
 npm-debug.log
 yarn-debug.log
 yarn-error.log
+yarn.lock
 
 # BUCK
 buck-out/

+ 0 - 1
android/build.gradle

@@ -74,7 +74,6 @@ android {
 repositories {
   mavenCentral()
   google()
-  maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
 }
 
 

+ 77 - 18
android/src/main/java/com/compdfkitpdf/reactnative/CompdfkitPdfModule.java

@@ -20,22 +20,20 @@ import com.compdfkit.tools.common.pdf.CPDFConfigurationUtils;
 import com.compdfkit.tools.common.pdf.CPDFDocumentActivity;
 import com.compdfkit.tools.common.pdf.config.CPDFConfiguration;
 import com.compdfkit.tools.common.utils.CFileUtils;
-import com.compdfkit.tools.common.utils.CLog;
-import com.compdfkit.tools.common.utils.CUriUtil;
-import com.facebook.react.bridge.Callback;
 import com.facebook.react.bridge.Promise;
 import com.facebook.react.bridge.ReactApplicationContext;
 import com.facebook.react.bridge.ReactContext;
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
 import com.facebook.react.bridge.ReactMethod;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
+/**
+ * RN and Android native ComPDFKit SDK interaction class
+ *
+ */
 public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
+
+  private static final String TAG = "ComPDFKit-RN";
+
   public static final String NAME = "ComPDFKit";
 
   public static final String ASSETS_SCHEME = "file://android_assets";
@@ -55,38 +53,103 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
     return NAME;
   }
 
+  /**
+   * Get the version number of the ComPDFKit SDK.<br/>
+   * For example: "2.0.0".<br/>
+   * <p></p>
+   * Usage example:<br/><br/>
+   * <pre>
+   * ComPDFKit.getVersionCode().then((versionCode : string) => {
+   *   console.log('ComPDFKit SDK Version:', versionCode)
+   * })
+   * </pre>
+   *
+   */
   @ReactMethod
   public void getVersionCode(final Promise promise) {
     promise.resolve(CPDFSdk.getSDKVersion());
   }
 
+  /**
+   * Get the build tag of the ComPDFKit PDF SDK.<br/>
+   * For example: "build_beta_2.0.0_42db96987_202404081007"<br/>
+   * <p></p>
+   *
+   * Usage example:<br/>
+   * <pre>
+
+   * ComPDFKit.getSDKBuildTag().then((buildTag : string) => {
+   *   console.log('ComPDFKit Build Tag:', buildTag)
+   * })
+   * </pre>
+   *
+   */
   @ReactMethod
   public void getSDKBuildTag(final Promise promise) {
     promise.resolve(CPDFSdk.getSDKBuildTag());
   }
 
+  /**
+   * Initialize the ComPDFKit PDF SDK using offline authentication.<br/>
+   * <p></p>
+   * Usage example:<br/>
+   * <pre>
+   * ComPDFKit.init_('license')
+   * </pre>
+   *
+   * @param license The offline license.
+   */
   @ReactMethod
   public void init_(String license) {
     CPDFSdk.init(mReactContext, license, true, (code, msg) -> {
-      Log.e("ComPDFKit", "init_: code:" + code +", msg:"+msg);
+      Log.e(TAG, "init_: code:" + code + ", msg:" + msg);
     });
   }
 
 
   /**
-   * Initialize the ComPDFKit SDK.
+   * Initialize the ComPDFKit PDF SDK using online authentication. <br/>
+   * Requires internet connection. Please ensure that the network permission has been added in [AndroidManifest.xml] file. <br/>
+   * {@link android.Manifest.permission#INTERNET} <br/>
+   * <p></p>
+   * Usage example:
+   * <pre>
+   *   ComPDFKit.initialize(androidLicense, iosLicense)
+   * </pre>
    *
-   * @param androidOnlineLicense The android platform compdfkit license key.
+   * @param androidOnlineLicense The online license for the ComPDFKit SDK on Android platform.
+   * @param iosOnlineLicense     The online license for the ComPDFKit SDK on iOS platform.
    */
   @ReactMethod
   public void initialize(String androidOnlineLicense, String iosOnlineLicense) {
     CPDFSdk.init(mReactContext, androidOnlineLicense, false, (code, msg) -> {
-      Log.e("ComPDFKit", "initialize: code:" + code +", msg:"+msg);
+      Log.e(TAG, "initialize: code:" + code + ", msg:" + msg);
     });
   }
 
+
   /**
-   * Display a PDF.
+   * Display a PDF.<br/>
+   *
+   * Usage example:<br/>
+   * <pre>
+   *   ComPDFKit.openDocument(document, password, configurationJson)
+   * </pre>
+   *
+   * (Android) For local storage file path: <br/>
+   * <pre>
+   *   document = "file:///storage/emulated/0/Download/sample.pdf";<br/>
+   * </pre>
+   *
+   * (Android) For content Uri: <br/>
+   * <pre>
+   *   document = "content://...";
+   * </pre>
+   *
+   * (Android) For assets path: <br/>
+   * <pre>
+   *   document = "file://android_assets/..."
+   * </pre>
    *
    * @param document          The document URI or file path.
    * @param password          The document password.
@@ -95,7 +158,6 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
   @ReactMethod
   public void openDocument(String document, String password, String configurationJson) {
     Intent intent = new Intent(mReactContext, CPDFDocumentActivity.class);
-    Log.e("ComPDFKit", "document= " + document);
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     parseDocument(document, intent);
     intent.putExtra(CPDFDocumentActivity.EXTRA_FILE_PASSWORD, password);
@@ -112,11 +174,8 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
       String fileName = strs[strs.length -1];
       String samplePDFPath = CFileUtils.getAssetsTempFile(mReactContext, assetsPath, fileName);
       intent.putExtra(CPDFDocumentActivity.EXTRA_FILE_PATH, samplePDFPath);
-      Log.e("ComPDFKit", "result , document= " + samplePDFPath);
-
     } else if (document.startsWith(CONTENT_SCHEME)) {
       Uri uri = Uri.parse(document);
-      Log.e("ComPDFKit", "result , document= " + uri.toString());
       intent.setData(uri);
     }
   }

File diff suppressed because it is too large
+ 1 - 2
example/src/App.tsx


+ 4 - 1
example/android/app/src/main/res/values/styles.xml

@@ -1,10 +1,13 @@
-<resources>
+<resources xmlns:tools="http://schemas.android.com/tools">
 
     <!-- Base application theme. -->
     <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
         <!-- Customize your theme here. -->
         <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
       <item name="android:statusBarColor">@color/tools_color_primary</item>
+      <item name="isLightTheme">true</item>
+      <item name="android:isLightTheme" tools:targetApi="q">true</item>
+      <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
     </style>
 
 </resources>

+ 8 - 10
example/android/build.gradle

@@ -5,14 +5,14 @@ buildscript {
     compileSdkVersion = 34
     targetSdkVersion = 34
     kotlinVersion = "1.8.0"
-    ndkVersion = "23.1.7779620"
-//    if (System.properties['os.arch'] == "aarch64") {
-//      // For M1 Users we need to use the NDK 24 which added support for aarch64
-//      ndkVersion = "24.0.8215888"
-//    } else {
-//      // Otherwise we default to the side-by-side NDK version from AGP.
-//      ndkVersion = "21.4.7075529"
-//    }
+//    ndkVersion = "23.1.7779620"
+    if (System.properties['os.arch'] == "aarch64") {
+      // For M1 Users we need to use the NDK 24 which added support for aarch64
+      ndkVersion = "24.0.8215888"
+    } else {
+      // Otherwise we default to the side-by-side NDK version from AGP.
+      ndkVersion = "21.4.7075529"
+    }
   }
   repositories {
     google()
@@ -30,8 +30,6 @@ allprojects {
   repositories {
     google()
     mavenCentral()
-    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
-
   }
 }
 

+ 1 - 1
example/index.js

@@ -1,5 +1,5 @@
 import { AppRegistry } from 'react-native';
-import App from './src/App';
+import App from './App';
 import { name as appName } from './app.json';
 
 AppRegistry.registerComponent(appName, () => App);

+ 2 - 2
example/package.json

@@ -1,7 +1,7 @@
 {
   "name": "react-native-compdfkit-pdf-example",
-  "version": "1.13.1",
-  "versionCode": "5",
+  "version": "2.0.1",
+  "versionCode": "6",
   "private": true,
   "scripts": {
     "android": "react-native run-android",

+ 2 - 61
package.json

@@ -1,30 +1,12 @@
 {
   "name": "react-native-compdfkit-pdf",
-  "version": "2.0.0",
+  "version": "2.0.1",
   "description": "ComPDFKit for React Native is a comprehensive SDK that allows you to quickly add PDF functionality to Android and iOS React Native applications.",
   "main": "lib/commonjs/index",
   "module": "lib/module/index",
   "types": "lib/typescript/src/index.d.ts",
   "react-native": "src/index",
   "source": "src/index",
-  "files": [
-    "src",
-    "lib",
-    "android",
-    "ios",
-    "cpp",
-    "*.podspec",
-    "!ios/build",
-    "!android/build",
-    "!android/gradle",
-    "!android/gradlew",
-    "!android/gradlew.bat",
-    "!android/local.properties",
-    "!**/__tests__",
-    "!**/__fixtures__",
-    "!**/__mocks__",
-    "!**/.*"
-  ],
   "scripts": {
     "example": "yarn workspace react-native-compdfkit-pdf-example",
     "test": "jest",
@@ -49,7 +31,7 @@
     "type": "git",
     "url": "https://github.com/ComPDFKit/compdfkit-pdf-sdk-react-native"
   },
-  "author": "ComPDFKit <youna@compdf.com> (https://github.com/ComPDFKIt)",
+  "author": "ComPDFKit <youna@compdf.com> (https://github.com/ComPDFKit)",
   "license": "SEE LICENSE IN LICENSE",
   "bugs": {
     "url": "https://www.compdf.com/support"
@@ -78,17 +60,6 @@
   "workspaces": [
     "example"
   ],
-  "packageManager": "yarn@3.6.1",
-  "engines": {
-    "node": ">= 18.0.0"
-  },
-  "jest": {
-    "preset": "react-native",
-    "modulePathIgnorePatterns": [
-      "<rootDir>/example/node_modules",
-      "<rootDir>/lib/"
-    ]
-  },
   "commitlint": {
     "extends": [
       "@commitlint/config-conventional"
@@ -111,36 +82,6 @@
       }
     }
   },
-  "eslintConfig": {
-    "root": true,
-    "extends": [
-      "@react-native",
-      "prettier"
-    ],
-    "rules": {
-      "prettier/prettier": [
-        "error",
-        {
-          "quoteProps": "consistent",
-          "singleQuote": true,
-          "tabWidth": 2,
-          "trailingComma": "es5",
-          "useTabs": false
-        }
-      ]
-    }
-  },
-  "eslintIgnore": [
-    "node_modules/",
-    "lib/"
-  ],
-  "prettier": {
-    "quoteProps": "consistent",
-    "singleQuote": true,
-    "tabWidth": 2,
-    "trailingComma": "es5",
-    "useTabs": false
-  },
   "react-native-builder-bob": {
     "source": "src",
     "output": "lib",

+ 0 - 10
yarn.lock

@@ -7697,15 +7697,6 @@ __metadata:
   languageName: node
   linkType: hard
 
-"pod-install@npm:*":
-  version: 0.2.0
-  resolution: "pod-install@npm:0.2.0"
-  bin:
-    pod-install: build/index.js
-  checksum: ecfe94d1285b42dd56fb03b9d1850d805f5626b8030acd32f2cb9ea6902e678deaefbb8475d2e307d0a6311159c6b5deea173adcc045c5ff6d58b377b0dcf1b8
-  languageName: node
-  linkType: hard
-
 "pod-install@npm:^0.1.0":
   version: 0.1.39
   resolution: "pod-install@npm:0.1.39"
@@ -7998,7 +7989,6 @@ __metadata:
   dependencies:
     "@types/react": "*"
     "@types/react-native": "*"
-    pod-install: "*"
     react: "*"
     react-native: "*"
     react-native-builder-bob: "*"