|
@@ -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);
|
|
|
}
|
|
|
}
|