Procházet zdrojové kódy

ComPDFKit(flutter) - 调整示例代码,修改弃用api

liuxiaolong před 3 týdny
rodič
revize
35fc5da52f

+ 16 - 0
CHANGELOG.md

@@ -1,3 +1,19 @@
+## 2.2.2
+* Added the features support for ComPDFKit PDF SDK for iOS iOS V2.2.2.
+* Added the features support for ComPDFKit PDF SDK for Android Android V2.2.2.
+* `CPDFDocument()` can now be used independently, without relying on `CPDFReaderWidget`, enhancing flexibility and ease of use.
+* Added the ability to save a watermark to the current PDF when adding it.
+* Fixed the inaccurate judgment issue in the `hasChange()` method.
+* Fixed an issue where some document text fields in forms were not displaying content.
+* Fixed an issue on the Android platform where Ink annotations became smaller after drawing.
+* Fixed an issue on the Android platform where the pen size shrank when drawing Ink annotations after zooming in on a page.
+* Fixed an input issue with the **LaBan Key** input method on the Android platform.
+* Fixed a potential crash issue on the Android platform when enabling the rotate function. 
+* Fixed a crash issue on the Android platform when importing XFDF annotations. 
+* Fixed an issue on the Android platform where annotations did not appear when printing with `document.printDocument()`. 
+* Fixed an issue on Android where the `saveAs()` method resulted in a “document cannot be edited” prompt after saving.
+
+
 ## 2.2.1
 * Added the features support for ComPDFKit PDF SDK for iOS [iOS V2.2.1](https://www.compdf.com/pdf-sdk/changelog-ios#v2-2-1).
 * Added the features support for ComPDFKit PDF SDK for Android [Android V2.2.1](https://www.compdf.com/pdf-sdk/changelog-android#v2-2-1).

+ 9 - 5
CONFIGURATION.md

@@ -784,10 +784,11 @@ This section is used to configure the types of forms enabled in the view's botto
 
 ##### Parameters
 
-| Name                    | Type          | Example | Description                                                  |
-| ----------------------- | ------------- | ------- | ------------------------------------------------------------ |
-| themeMode               | CPDFThemeMode | light   | Set the view theme style, support `light`, `dark`, `system`, the default is `light` theme<br />**ComPDFKit SDK for Flutter:** => 2.0.2<br />Only Android Platform. |
-| fileSaveExtraFontSubset | boolean       | true    | When saving a document, whether to save the used font set together with the document. |
+| Name                    | Type                | Example                      | Description                                                  |
+| ----------------------- | ------------------- | ---------------------------- | ------------------------------------------------------------ |
+| themeMode               | CPDFThemeMode       | light                        | Set the view theme style, support `light`, `dark`, `system`, the default is `light` theme<br />**ComPDFKit SDK for Flutter:** => 2.0.2<br />Only Android Platform. |
+| fileSaveExtraFontSubset | boolean             | true                         | When saving a document, whether to save the used font set together with the document. |
+| watermark               | CPDFWatermarkConfig | {   "saveAsNewFile" : true } | The user can configure the watermark addition popup, allowing them to choose whether to save the watermark directly to the current document or save it to a different directory.<br>**true**: Save to a different directory<br>**false**: Add to the current document directly |
 
 ##### themeMode Constants
 
@@ -1066,7 +1067,10 @@ This section is used to configure the types of forms enabled in the view's botto
   },
   "global" : {
     "themeMode" : "system",
-    "fileSaveExtraFontSubset" : true
+    "fileSaveExtraFontSubset" : true,
+    "watermark": {
+      "saveAsNewFile" : true
+    }
   }
 }
 ```

+ 6 - 6
README.md

@@ -151,7 +151,7 @@ Alternatively you can update the `AndroidManifest.xml` file to use `FlutterFragm
  dependencies:
    flutter:
      sdk: flutter
-+  compdfkit_flutter: ^2.2.1
++  compdfkit_flutter: ^2.2.2
 ```
 
 8. Add the PDF documents you want to display in the project
@@ -197,7 +197,7 @@ cd example
  dependencies:
    flutter:
      sdk: flutter
-+  compdfkit_flutter: ^2.2.1
++  compdfkit_flutter: ^2.2.2
 ```
 
 4. Open your project's Podfile in a text editor:
@@ -220,8 +220,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/2.2.1.podspec'
-+  pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.1.podspec'
++  pod 'ComPDFKit_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.2.podspec'
++  pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.2.podspec'
 
  end
 ```
@@ -557,8 +557,8 @@ target 'PDFView_RN' do
     # Pods for testing
   end
 
-+  pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.1'
-+  pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.1'
++  pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.2'
++  pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.2'
 
   # Enables Flipper.
   #

+ 1 - 1
android/build.gradle

@@ -45,7 +45,7 @@ android {
         implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
 
         // dependencies compdfkit pdf sdk
-        api 'com.compdf:compdfkit-tools:2.2.2-SNAPSHOT'
+        api 'com.compdf:compdfkit-tools:2.2.2'
 
         testImplementation 'junit:junit:4.13.2'
         testImplementation 'org.mockito:mockito-core:5.0.0'

+ 2 - 0
example/.gitignore

@@ -5,9 +5,11 @@
 *.swp
 .DS_Store
 .atom/
+.build/
 .buildlog/
 .history
 .svn/
+.swiftpm/
 migrate_working_dir/
 
 # IntelliJ related

+ 3 - 2
example/android/app/build.gradle

@@ -65,6 +65,7 @@ android {
 
     buildTypes {
         release {
+            minifyEnabled true
             signingConfig signingConfigs.release
             proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
         }
@@ -78,8 +79,8 @@ flutter {
 dependencies {
 
     api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
-    implementation 'com.google.android.material:material:1.8.0'
-    implementation 'androidx.appcompat:appcompat:1.6.1'
+    implementation 'com.google.android.material:material:1.12.0'
+    implementation 'androidx.appcompat:appcompat:1.7.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
 
 }

+ 25 - 0
example/android/app/proguard-rules.pro

@@ -0,0 +1,25 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
+-keep class com.compdfkit.ui.** {*;}
+-keep class com.compdfkit.core.** {*;}
+-keep class com.compdfkit.tools.** {*;}
+-keep interface com.compdfkit.tools.**{*;}

+ 1 - 1
example/android/config.gradle

@@ -3,6 +3,6 @@ ext {
             COMPILESDK: 33,
             MINSDK: 21,
             TARGETSDK: 33,
-            VERSIONCODE: 14
+            VERSIONCODE: 15
     ]
 }

+ 1 - 0
example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

@@ -59,6 +59,7 @@
       ignoresPersistentStateOnLaunch = "NO"
       debugDocumentVersioning = "YES"
       debugServiceExtension = "internal"
+      enableGPUValidationMode = "1"
       allowLocationSimulation = "YES">
       <BuildableProductRunnable
          runnableDebuggingMode = "0">

+ 1 - 1
example/ios/Runner/AppDelegate.swift

@@ -1,7 +1,7 @@
 import UIKit
 import Flutter
 
-@UIApplicationMain
+@main
 @objc class AppDelegate: FlutterAppDelegate {
   override func application(
     _ application: UIApplication,

+ 1 - 14
example/lib/cpdf_document_examples.dart

@@ -10,7 +10,6 @@
 
 import 'package:compdfkit_flutter_example/examples.dart';
 import 'package:compdfkit_flutter_example/examples/cpdf_document_open_pdf_example.dart';
-import 'package:compdfkit_flutter_example/examples/cpdf_document_save_as_example.dart';
 import 'package:flutter/material.dart';
 
 class CPDFDocumentExamples extends StatelessWidget {
@@ -40,18 +39,6 @@ class CPDFDocumentExamples extends StatelessWidget {
           onTap: () {
             goTo(const CPDFDocumentOpenPDFExample(), context);
           },
-        ),
-        ListTile(
-          title: const Text('Save As Issues'),
-          onTap: () async {
-            String? document = await pickDocument();
-            if (document != null) {
-              debugPrint('document:$document');
-              if (context.mounted) {
-                goTo(CPDFSaveAsExample(document: document), context);
-              }
-            }
-          },
-        ),
+        )
       ];
 }

+ 0 - 7
example/lib/cpdf_reader_widget_example.dart

@@ -36,13 +36,6 @@ class _CPDFReaderWidgetExampleState extends State<CPDFReaderWidgetExample> {
                 Navigator.pop(context);
               },
               icon: const Icon(Icons.arrow_back)),
-          actions: [
-            IconButton(
-                onPressed: () async {
-                  await _controller.document.printDocument();
-                },
-                icon: const Icon(Icons.print))
-          ],
         ),
         body: CPDFReaderWidget(
           document: widget.documentPath,

+ 1 - 1
example/lib/examples/cpdf_document_open_pdf_example.dart

@@ -105,7 +105,7 @@ class _CPDFDocumentExampleState extends State<CPDFDocumentOpenPDFExample> {
             content: TextField(
               controller: _textEditingController,
               textInputAction: TextInputAction.done,
-              decoration: const InputDecoration(hintText: 'compdfkit'),
+              decoration: const InputDecoration(hintText: 'compdfkit', hintStyle: TextStyle(color: Colors.black12)),
             ),
             actions: [
               TextButton(

+ 0 - 116
example/lib/examples/cpdf_document_save_as_example.dart

@@ -1,116 +0,0 @@
-/*
- * Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
- *
- * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- * This notice may not be removed from this file.
- *
- */
-
-import 'dart:io';
-
-import 'package:compdfkit_flutter/compdfkit.dart';
-import 'package:compdfkit_flutter/configuration/cpdf_configuration.dart';
-import 'package:compdfkit_flutter/widgets/cpdf_reader_widget.dart';
-import 'package:compdfkit_flutter/widgets/cpdf_reader_widget_controller.dart';
-import 'package:compdfkit_flutter_example/cpdf_reader_widget_example.dart';
-import 'package:compdfkit_flutter_example/examples.dart';
-import 'package:flutter/material.dart';
-
-class CPDFSaveAsExample extends StatefulWidget {
-  final String document;
-
-  const CPDFSaveAsExample({super.key, required this.document});
-
-
-  @override
-  State<CPDFSaveAsExample> createState() => _CPDFSaveAsExampleState();
-}
-
-class _CPDFSaveAsExampleState extends State<CPDFSaveAsExample> {
-  late CPDFReaderWidgetController controller;
-
-  @override
-  void initState() {
-    super.initState();
-  }
-
-  void initPDFPath() async {}
-  @override
-  Widget build(BuildContext context) {
-    return Scaffold(
-        appBar: AppBar(
-          title: const Text('Save As issues'),
-          actions: [
-            IconButton(
-                onPressed: () async {
-                  // await controller.document.save();
-
-                  final tempDir = await ComPDFKit.getTemporaryDirectory();
-                  String savePath = '${tempDir.path}/test_2.pdf';
-                  bool saveResult = await controller.document.saveAs(savePath);
-                  if (saveResult) {
-                    var jump = await _showSaveResultDialog(savePath);
-                    if (jump != null && context.mounted) {
-                      goTo(CPDFReaderWidgetExample(documentPath: jump), context);
-                    }
-                  }
-                },
-                icon: const Icon(Icons.download)),
-            IconButton(
-                onPressed: () async {
-
-                  final tempDir = await ComPDFKit.getTemporaryDirectory();
-                  String savePath = '${tempDir.path}/test_2.pdf';
-                  final file = File(savePath);
-                  if(await file.exists()){
-                    await file.delete();
-                  }
-
-                  // File xfdfFile = await extractAsset(context, 'pdfs/test.xfdf');
-                  //
-                  // // android Uri:
-                  // //String xfdfFile = "content://xxx";
-                  //
-                  // bool result = await controller.document
-                  //     .importAnnotations(xfdfFile.path);
-                  // debugPrint('ComPDFKit:Document: importAnnotations:$result');
-                },
-                icon: const Icon(Icons.settings_ethernet_rounded)),
-
-          ],
-        ),
-        body: CPDFReaderWidget(
-            document: widget.document,
-            configuration: CPDFConfiguration(),
-            onCreated: (controller) {
-              setState(() {
-                this.controller = controller;
-              });
-            }));
-  }
-
-  Future<String?> _showSaveResultDialog(String path) async {
-    return await showDialog(
-        context: context,
-        builder: (context) {
-          return AlertDialog(
-            title: const Text('Save Result'),
-            content: Text('Save Path:$path'),
-            actions: [
-              TextButton(
-                  onPressed: () {
-                    Navigator.pop(context, null);
-                  },
-                  child: const Text('Cancel')),
-              TextButton(
-                  onPressed: () {
-                    Navigator.pop(context, path);
-                  },
-                  child: const Text('Jump'))
-            ],
-          );
-        });
-  }
-}

+ 8 - 6
lib/util/extension/cpdf_color_extension.dart

@@ -13,14 +13,16 @@ import 'package:flutter/material.dart';
 /// extension [Color] class
 /// toHex: Colors.white.toHex() => '#FFFFFFFF'
 /// formHex: '#FFFFFF' => Colors.white
-extension HexColor on Color{
+extension HexColor on Color {
 
   /// Colors.white.toHex() => '#FFFFFFFF'
-  String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
-      '${alpha.toRadixString(16).padLeft(2, '0')}'
-      '${red.toRadixString(16).padLeft(2, '0')}'
-      '${green.toRadixString(16).padLeft(2, '0')}'
-      '${blue.toRadixString(16).padLeft(2, '0')}';
+  String toHex({bool leadingHashSign = true}) {
+    final hexA = (a * 255).round().toRadixString(16).padLeft(2, '0');
+    final hexR = (r * 255).round().toRadixString(16).padLeft(2, '0');
+    final hexG = (g * 255).round().toRadixString(16).padLeft(2, '0');
+    final hexB = (b * 255).round().toRadixString(16).padLeft(2, '0');
+    return '${leadingHashSign ? '#' : ''}$hexA$hexR$hexG$hexB';
+  }
 
   /// formHex: '#FFFFFF' => Colors.white
   static Color fromHex(String hexString) {