Browse Source

ComPDFKit(flutter) - 1.更新安卓SDK p1

liuxiaolong 1 year ago
parent
commit
14ef6a787a

+ 129 - 77
README.md

@@ -122,7 +122,7 @@ flutter create --org com.compdfkit.flutter example
 cd example
 ```
 
-3. open  `example/android/app/src/main/AndroidManifest.xml` , add`ComPDFKit License` and `Storage Permission`:
+3. open  `example/android/app/src/main/AndroidManifest.xml` , add `Storage Permission`:
 
 ```diff
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
@@ -132,17 +132,6 @@ cd example
 +    <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>
 ```
@@ -171,7 +160,7 @@ open android/app/build.gradle
  dependencies:
    flutter:
      sdk: flutter
-+  compdfkit_flutter: ^1.0.0
++  compdfkit_flutter: ^1.11.0
 ```
 
 7. From the terminal app, run the following command to get all the packages:
@@ -186,6 +175,7 @@ flutter pub get
 import 'dart:io';
 
 import 'package:compdfkit_flutter/compdfkit.dart';
+import 'package:compdfkit_flutter/cpdf_configuration.dart';
 
 import 'package:flutter/material.dart';
 
@@ -210,38 +200,67 @@ class _MyAppState extends State<MyApp> {
   }
 
   void _init() async {
-    // Please replace it with your ComPDFKit license
-    ComPDFKit.init('your license key', 'your license secret');
+    ComPDFKit.init('your compdfkit key');
   }
 
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
       home: Scaffold(
-        body: SafeArea(
-          child: Center(
-            child: ElevatedButton(
-              onPressed: () async {
-                showDocument(context);
-              },
-              child: const Text(
-                'Open Document',
-                style: TextStyle(color: Colors.white),
-              )),
-          ))),
+          body: SafeArea(
+              child: Center(
+        child: ElevatedButton(
+            onPressed: () async {
+              showDocument(context);
+            },
+            child: const Text(
+              'Open Document',
+              style: TextStyle(color: Colors.white),
+            )),
+      ))),
     );
   }
 
   void showDocument(BuildContext context) async {
     final bytes = await DefaultAssetBundle.of(context).load(DOCUMENT_PATH);
     final list = bytes.buffer.asUint8List();
-
     final tempDir = await ComPDFKit.getTemporaryDirectory();
-    final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
+    var pdfsDir = Directory('${tempDir.path}/pdfs');
+    pdfsDir.createSync(recursive: true);
 
-    final file = await File(tempDocumentPath).create(recursive: true);
-    file.writeAsBytesSync(list);
-    ComPDFKit.openDocument(tempDocumentPath);
+    final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
+    final file = File(tempDocumentPath);
+    if (!file.existsSync()) {
+      file.create(recursive: true);
+      file.writeAsBytesSync(list);
+    }
+    var configuration = CPDFConfiguration();
+    // How to disable functionality:
+    // setting the default display mode when opening
+    //      configuration.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.annotations);
+    // top toolbar configuration:
+    // android:
+    //      configuration.toolbarConfig = const ToolbarConfig(androidAvailableActions: [
+    //           ToolbarAction.thumbnail, ToolbarAction.bota, 
+    //           ToolbarAction.search, ToolbarAction.menu
+    //      ],
+    //      availableMenus: [
+    //        ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
+    //      ]);
+    // iOS:
+    //      configuration.toolbarConfig = const ToolbarConfig(iosLeftBarAvailableActions: [
+    //          ToolbarAction.back, ToolbarAction.thumbnail
+    //      ],
+    //      iosRightBarAvailableActions: [
+    //        ToolbarAction.bota, ToolbarAction.search, ToolbarAction.menu
+    //      ],
+    //      availableMenus: [
+    //        ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
+    //      ]);
+    // readerview configuration
+    //      configuration.readerViewConfig = const ReaderViewConfig(linkHighlight: true, formFieldHighlight: true);
+    ComPDFKit.openDocument(tempDocumentPath,
+        password: '', configuration: configuration);
   }
 }
 ```
@@ -292,7 +311,7 @@ cd example
  dependencies:
    flutter:
      sdk: flutter
-+  compdfkit_flutter: ^1.0.0
++  compdfkit_flutter: ^1.11.0
 ```
 
 7. From the terminal app, run the following command to get all the packages:
@@ -307,7 +326,7 @@ flutter pub get
 open ios/Podfile
 ```
 
-9. Update the platform to iOS 10 and add the ComPDFKit Podspec:
+9. Update the platform to iOS 11 and add the ComPDFKit Podspec:
 
 ```diff
 - platform :ios, '9.0'
@@ -318,8 +337,8 @@ open ios/Podfile
    use_modular_headers!`
 
    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
-+  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'
++  pod 'ComPDFKit_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/1.11.0.podspec'
++  pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/1.11.0.podspec'
 
  end
 ```
@@ -330,12 +349,13 @@ open ios/Podfile
 pod install
 ```
 
-10. Open `lib/main.dart` and replace the entire content with the following code. And fill in the license provided to you in the `ComPDFKit.init` method, this simple example will load a PDF document from the local device file system.
+11. Open `lib/main.dart` and replace the entire content with the following code. And fill in the license provided to you in the `ComPDFKit.init` method, this simple example will load a PDF document from the local device file system.
 
 ```dart
 import 'dart:io';
 
 import 'package:compdfkit_flutter/compdfkit.dart';
+import 'package:compdfkit_flutter/cpdf_configuration.dart';
 
 import 'package:flutter/material.dart';
 
@@ -360,43 +380,73 @@ class _MyAppState extends State<MyApp> {
   }
 
   void _init() async {
-		// Please replace it with your ComPDFKit license
-    ComPDFKit.init('your license key', 'your license secret');
+    // Please replace it with your ComPDFKit license
+    ComPDFKit.init('your compdfkit key');
   }
 
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
       home: Scaffold(
-        body: SafeArea(
-          child: Center(
-            child: ElevatedButton(
-              onPressed: () async {
-                showDocument(context);
-              },
-              child: const Text(
-                'Open Document',
-                style: TextStyle(color: Colors.white),
-              )),
-          ))),
+          body: SafeArea(
+              child: Center(
+        child: ElevatedButton(
+            onPressed: () async {
+              showDocument(context);
+            },
+            child: const Text(
+              'Open Document',
+              style: TextStyle(color: Colors.white),
+            )),
+      ))),
     );
   }
 
   void showDocument(BuildContext context) async {
     final bytes = await DefaultAssetBundle.of(context).load(DOCUMENT_PATH);
     final list = bytes.buffer.asUint8List();
-
     final tempDir = await ComPDFKit.getTemporaryDirectory();
-    final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
+    var pdfsDir = Directory('${tempDir.path}/pdfs');
+    pdfsDir.createSync(recursive: true);
 
-    final file = await File(tempDocumentPath).create(recursive: true);
-    file.writeAsBytesSync(list);
-    ComPDFKit.openDocument(tempDocumentPath);
+    final tempDocumentPath = '${tempDir.path}/$DOCUMENT_PATH';
+    final file = File(tempDocumentPath);
+    if (!file.existsSync()) {
+      file.create(recursive: true);
+      file.writeAsBytesSync(list);
+    }
+    var configuration = CPDFConfiguration();
+    // How to disable functionality:
+    // setting the default display mode when opening
+    //      configuration.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.annotations);
+    // top toolbar configuration:
+    // android:
+    //      configuration.toolbarConfig = const ToolbarConfig(androidAvailableActions: [
+    //           ToolbarAction.thumbnail, ToolbarAction.bota, 
+    //           ToolbarAction.search, ToolbarAction.menu
+    //      ],
+    //      availableMenus: [
+    //        ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
+    //      ]);
+    // iOS:
+    //      configuration.toolbarConfig = const ToolbarConfig(iosLeftBarAvailableActions: [
+    //          ToolbarAction.back, ToolbarAction.thumbnail
+    //      ],
+    //      iosRightBarAvailableActions: [
+    //        ToolbarAction.bota, ToolbarAction.search, ToolbarAction.menu
+    //      ],
+    //      availableMenus: [
+    //        ToolbarMenuAction.viewSettings, ToolbarMenuAction.documentInfo, ToolbarMenuAction.security,
+    //      ]);
+    // readerview configuration:
+    //      configuration.readerViewConfig = const ReaderViewConfig(linkHighlight: true, formFieldHighlight: 		true);
+    ComPDFKit.openDocument(tempDocumentPath,
+        password: '', configuration: configuration);
   }
 }
 ```
 
-9. Add the PDF documents you want to display in the project
+12. Add the PDF documents you want to display in the project
 
 * create a `pdf` directory
 
@@ -406,7 +456,7 @@ class _MyAppState extends State<MyApp> {
 
 * Copy your example document into the newly created `pdfs` directory and name it `PDF_Document.pdf`
 
-10. Specify the `assets` directory in `pubspec.yaml`
+13. Specify the `assets` directory in `pubspec.yaml`
 
 ```diff
  flutter:
@@ -414,35 +464,33 @@ class _MyAppState extends State<MyApp> {
 +    - pdfs/
 ```
 
-11. To protect user privacy,
+14. To protect user privacy,
 
-    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.
+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.
 
-    ![](screenshots/1-8.png)
+![](screenshots/1-8.png)
 
-    ```objective-c
-    <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>
-    ```
+```objective-c
+<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>
+```
 
-12. Start your Android emulator, or connect a device.
+15. Start your Android emulator, or connect a device.
 
 ```bash
 flutter emulators --launch apple_ios_simulator
 ```
 
-13. Run the app with:
+16. Run the app with:
 
 ```bash
 flutter run
@@ -450,9 +498,13 @@ flutter run
 
 
 
-## 4 Support
 
-### 4.1 Reporting Problems
+
+
+
+## 3 Support
+
+### 3.1 Reporting Problems
 
 Thank you for your interest in ComPDFKit, 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 Flutter PDF Library, please submit the problem report to the [ComPDFKit team](https://www.compdf.com/support). More information as follows would help us to solve your problem:
 
@@ -463,7 +515,7 @@ Thank you for your interest in ComPDFKit, the only easy-to-use but powerful deve
 
 
 
-### 4.2 Contact Information
+### 3.2 Contact Information
 
 **Home Link:**
 

BIN
android/libs/ComPDFKit-UI.aar


BIN
android/libs/ComPDFKit.aar


BIN
android/libs/ComPDFKit_Tools.aar


+ 54 - 20
android/src/main/java/com/compdfkit/flutter/compdfkit_flutter/pdf/CPDFDocumentActivity.java

@@ -15,6 +15,7 @@ import static com.compdfkit.ui.contextmenu.CPDFContextMenuShowHelper.ReplaceEdit
 
 import android.Manifest;
 import android.content.Intent;
+import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.text.TextUtils;
@@ -62,9 +63,11 @@ import com.compdfkit.tools.signature.bean.CPDFDocumentSignInfo;
 import com.compdfkit.tools.signature.info.signlist.CPDFCertDigitalSignListDialog;
 import com.compdfkit.tools.viewer.pdfsearch.CSearchResultDialogFragment;
 import com.compdfkit.ui.contextmenu.IContextMenuShowListener;
+import com.compdfkit.ui.proxy.CPDFBaseAnnotImpl;
 import com.compdfkit.ui.proxy.form.CPDFComboboxWidgetImpl;
 import com.compdfkit.ui.proxy.form.CPDFListboxWidgetImpl;
 import com.compdfkit.ui.proxy.form.CPDFPushbuttonWidgetImpl;
+import com.compdfkit.ui.proxy.form.CPDFSignatureWidgetImpl;
 import com.compdfkit.ui.reader.CPDFPageView;
 import com.compdfkit.ui.reader.CPDFReaderView;
 
@@ -121,38 +124,55 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
         setContentView(binding.getRoot());
         screenManager.bind(binding);
         //Extract PDF files from the Android assets folder
-        initPDFView();
         parseConfiguration();
-        initToolBarView();
-        initSearchBar();
-        initAnnotToolbar();
-        initFormToolbar();
-        initEditBar();
-        initSignatureToolbar();
-        onDoNext();
+        initDocument(()->{
+            initPDFView();
+            initToolBarView();
+            initSearchBar();
+            initAnnotToolbar();
+            initFormToolbar();
+            initEditBar();
+            initSignatureToolbar();
+            applyConfiguration();
+            onDoNext();
+        });
     }
 
-    private void initDocument() {
+    private void initDocument(CInitPDFRequestListener initPDFRequestListener) {
         String password = getIntent().getStringExtra(EXTRA_FILE_PASSWORD);
         if (!TextUtils.isEmpty(getIntent().getStringExtra(EXTRA_FILE_PATH))) {
             String path = getIntent().getStringExtra(EXTRA_FILE_PATH);
             binding.pdfView.openPDF(path, password);
-            binding.editToolBar.setEditMode(false);
+            if (initPDFRequestListener != null) {
+                initPDFRequestListener.success();
+            }
         } else if (getIntent().getData() != null) {
             CFileUtils.takeUriPermission(this, getIntent().getData());
             binding.pdfView.openPDF(getIntent().getData(), password);
-            binding.editToolBar.setEditMode(false);
+            if (initPDFRequestListener != null) {
+                initPDFRequestListener.success();
+            }
+        } else if (getIntent().getClipData().getItemCount() > 0 && getIntent().getClipData().getItemAt(0) != null) {
+            Uri uri = getIntent().getClipData().getItemAt(0).getUri();
+            CFileUtils.takeUriPermission(this, uri);
+            binding.pdfView.openPDF(uri, password);
+            if (initPDFRequestListener != null) {
+                initPDFRequestListener.success();
+            }
         } else {
             CExtractAssetFileTask.extract(this, QUICK_START_GUIDE, QUICK_START_GUIDE, (filePath) -> {
                         binding.pdfView.openPDF(filePath);
-                        binding.editToolBar.setEditMode(false);
+                        runOnUiThread(()->{
+                            if (initPDFRequestListener != null) {
+                                initPDFRequestListener.success();
+                            }
+                        });
                     }
             );
         }
     }
 
     private void initPDFView() {
-        initDocument();
         binding.pdfView.getCPdfReaderView().setMinScaleEnable(false);
         initAnnotationAttr(binding.pdfView);
         initFormAttr(binding.pdfView);
@@ -296,7 +316,8 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
                             showToolbarMenuDialog(v);
                         });
                         break;
-                    default:break;
+                    default:
+                        break;
                 }
             }
         }
@@ -348,6 +369,7 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
 
     private void initSearchBar() {
         binding.pdfSearchToolBar.initWithPDFView(binding.pdfView);
+
         binding.pdfSearchToolBar.onSearchQueryResults(list -> {
             CSearchResultDialogFragment searchResultDialog = new CSearchResultDialogFragment();
             searchResultDialog.show(getSupportFragmentManager(), "searchResultDialogFragment");
@@ -375,6 +397,7 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
             return;
         }
         binding.editToolBar.initWithPDFView(binding.pdfView);
+        binding.editToolBar.setEditMode(false);
         binding.editToolBar.setEditPropertyBtnClickListener((view) -> {
             int type = binding.pdfView.getCPdfReaderView().getSelectAreaType();
             CStyleType styleType = CStyleType.UNKNOWN;
@@ -427,6 +450,9 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
         } else {
             cpdfConfiguration = CPDFConfigurationUtils.normalConfig();
         }
+    }
+
+    private void applyConfiguration() {
         if (cpdfConfiguration.readerViewConfig != null) {
             CPDFConfiguration.ReaderViewConfig readerViewConfig = cpdfConfiguration.readerViewConfig;
             binding.pdfView.getCPdfReaderView().setLinkHighlight(readerViewConfig.linkHighlight);
@@ -436,6 +462,9 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
             CPDFConfiguration.ModeConfig modeConfig = cpdfConfiguration.modeConfig;
             if (modeConfig.initialViewMode != CPreviewMode.PageEdit) {
                 setPreviewMode(modeConfig.initialViewMode);
+                if (modeConfig.initialViewMode == CPreviewMode.Edit) {
+                    binding.editToolBar.setEditMode(true);
+                }
             } else {
                 setPreviewMode(CPreviewMode.Viewer);
                 showPageEdit(binding.pdfView, true, () -> {
@@ -543,7 +572,8 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
                             }
                         });
                         break;
-                    default:break;
+                    default:
+                        break;
                 }
             }
         }
@@ -660,7 +690,7 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
         CDocumentEncryptionDialog documentEncryptionDialog = CDocumentEncryptionDialog.newInstance();
         documentEncryptionDialog.setDocument(binding.pdfView.getCPdfReaderView().getPDFDocument());
         documentEncryptionDialog.setEncryptionResultListener((isRemoveSecurity, result, filePath, passowrd) -> {
-            binding.pdfView.openPDF(filePath, passowrd);
+            binding.pdfView.openPDF(filePath);
             documentEncryptionDialog.dismiss();
             int msgResId;
             if (isRemoveSecurity) {
@@ -690,14 +720,18 @@ public class CPDFDocumentActivity extends CBasicPDFActivity {
         }
     }
 
-    public static class CSignatureWidgetImpl extends SignatureWidgetImpl{
+    public static class CSignatureWidgetImpl extends SignatureWidgetImpl {
         @Override
         public CPreviewMode getCurrentMode() {
-            if (readerView.getContext() instanceof CPDFDocumentActivity){
-               return  ((CPDFDocumentActivity)readerView.getContext()).binding.pdfToolBar.getMode();
-            }else {
+            if (readerView.getContext() instanceof CPDFDocumentActivity) {
+                return ((CPDFDocumentActivity) readerView.getContext()).binding.pdfToolBar.getMode();
+            } else {
                 return CPreviewMode.Viewer;
             }
         }
     }
+
+    interface CInitPDFRequestListener {
+        void success();
+    }
 }

BIN
example/android/app/libs/ComPDFKit-UI.aar


BIN
example/android/app/libs/ComPDFKit.aar


BIN
example/android/app/libs/ComPDFKit_Tools.aar


File diff suppressed because it is too large
+ 28 - 1
example/lib/main.dart


+ 6 - 3
lib/cpdf_configuration.dart

@@ -24,11 +24,11 @@ import 'dart:convert';
 ///
 /// ```
 class CPDFConfiguration {
-  final ModeConfig modeConfig;
+  ModeConfig modeConfig;
 
-  final ToolbarConfig toolbarConfig;
+  ToolbarConfig toolbarConfig;
 
-  final ReaderViewConfig readerViewConfig;
+  ReaderViewConfig readerViewConfig;
 
   CPDFConfiguration(
       {this.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.viewer),
@@ -119,9 +119,12 @@ class ToolbarConfig {
       };
 }
 
+/// pdf readerView configuration
 class ReaderViewConfig {
+  // Highlight hyperlink annotations in pdf
   final bool linkHighlight;
 
+  // Highlight hyperlink form field
   final bool formFieldHighlight;
 
   const ReaderViewConfig(