Skip to content

Commit 60eb872

Browse files
committed
compdfkit_flutter 2.2.2
1 parent d3e6a55 commit 60eb872

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+763
-271
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 2.2.2
2+
* Added the features support for ComPDFKit PDF SDK for iOS iOS V2.2.2.
3+
* Added the features support for ComPDFKit PDF SDK for Android Android V2.2.2.
4+
* `CPDFDocument()` can now be used independently, without relying on `CPDFReaderWidget`, enhancing flexibility and ease of use.
5+
* Added the ability to save a watermark to the current PDF when adding it.
6+
* Fixed the inaccurate judgment issue in the `hasChange()` method.
7+
* Fixed an issue where some document text fields in forms were not displaying content.
8+
* Fixed an issue on the Android platform where Ink annotations became smaller after drawing.
9+
* Fixed an issue on the Android platform where the pen size shrank when drawing Ink annotations after zooming in on a page.
10+
* Fixed an input issue with the **LaBan Key** input method on the Android platform.
11+
* Fixed a potential crash issue on the Android platform when enabling the rotate function.
12+
* Fixed a crash issue on the Android platform when importing XFDF annotations.
13+
* Fixed an issue on the Android platform where annotations did not appear when printing with `document.printDocument()`.
14+
* Fixed an issue on Android where the `saveAs()` method resulted in a “document cannot be edited” prompt after saving.
15+
16+
117
## 2.2.1
218
* 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).
319
* 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).

CONFIGURATION.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,11 @@ This section is used to configure the types of forms enabled in the view's botto
784784

785785
##### Parameters
786786

787-
| Name | Type | Example | Description |
788-
| ----------------------- | ------------- | ------- | ------------------------------------------------------------ |
789-
| 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. |
790-
| fileSaveExtraFontSubset | boolean | true | When saving a document, whether to save the used font set together with the document. |
787+
| Name | Type | Example | Description |
788+
| ----------------------- | ------------------- | ---------------------------- | ------------------------------------------------------------ |
789+
| 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. |
790+
| fileSaveExtraFontSubset | boolean | true | When saving a document, whether to save the used font set together with the document. |
791+
| 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 |
791792

792793
##### themeMode Constants
793794

@@ -1066,7 +1067,10 @@ This section is used to configure the types of forms enabled in the view's botto
10661067
},
10671068
"global" : {
10681069
"themeMode" : "system",
1069-
"fileSaveExtraFontSubset" : true
1070+
"fileSaveExtraFontSubset" : true,
1071+
"watermark": {
1072+
"saveAsNewFile" : true
1073+
}
10701074
}
10711075
}
10721076
```

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Alternatively you can update the `AndroidManifest.xml` file to use `FlutterFragm
151151
dependencies:
152152
flutter:
153153
sdk: flutter
154-
+ compdfkit_flutter: ^2.2.1
154+
+ compdfkit_flutter: ^2.2.2
155155
```
156156

157157
8. Add the PDF documents you want to display in the project
@@ -197,7 +197,7 @@ cd example
197197
dependencies:
198198
flutter:
199199
sdk: flutter
200-
+ compdfkit_flutter: ^2.2.1
200+
+ compdfkit_flutter: ^2.2.2
201201
```
202202

203203
4. Open your project's Podfile in a text editor:
@@ -220,8 +220,8 @@ open ios/Podfile
220220
use_modular_headers!`
221221

222222
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
223-
+ pod 'ComPDFKit_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.1.podspec'
224-
+ pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.1.podspec'
223+
+ pod 'ComPDFKit_Tools', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.2.podspec'
224+
+ pod 'ComPDFKit', podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.2.podspec'
225225

226226
end
227227
```
@@ -557,8 +557,8 @@ target 'PDFView_RN' do
557557
# Pods for testing
558558
end
559559

560-
+ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.1'
561-
+ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.1'
560+
+ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.2'
561+
+ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.2'
562562

563563
# Enables Flipper.
564564
#

android/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ buildscript {
55
repositories {
66
google()
77
mavenCentral()
8+
mavenLocal()
9+
810
}
911

1012
dependencies {
@@ -16,14 +18,17 @@ rootProject.allprojects {
1618
repositories {
1719
google()
1820
mavenCentral()
21+
mavenLocal()
22+
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
23+
1924
}
2025
}
2126

2227
apply plugin: 'com.android.library'
2328

2429
android {
2530
compileSdk 33
26-
31+
namespace "com.compdfkit.flutter.compdfkit_flutter"
2732
compileOptions {
2833
sourceCompatibility JavaVersion.VERSION_1_8
2934
targetCompatibility JavaVersion.VERSION_1_8
@@ -40,7 +45,7 @@ android {
4045
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4146

4247
// dependencies compdfkit pdf sdk
43-
api 'com.compdf:compdfkit-tools:2.2.1'
48+
api 'com.compdf:compdfkit-tools:2.2.2'
4449

4550
testImplementation 'junit:junit:4.13.2'
4651
testImplementation 'org.mockito:mockito-core:5.0.0'

android/src/main/java/com/compdfkit/flutter/compdfkit_flutter/constants/CPDFConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public static class ChannelMethod {
150150
public static final String REMOVE_ALL_WATERMARKS = "remove_all_watermarks";
151151
public static final String GET_ENCRYPT_ALGORITHM = "get_encrypt_algorithm";
152152
public static final String SET_IMPORT_FONT_DIRECTORY = "set_import_font_directory";
153+
public static final String CREATE_DOCUMENT_PLUGIN = "create_document_plugin";
154+
153155
}
154156

155157
}

android/src/main/java/com/compdfkit/flutter/compdfkit_flutter/plugin/CPDFDocumentPlugin.java

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@
4040
import android.graphics.Color;
4141
import android.net.Uri;
4242
import android.os.Environment;
43+
import android.print.PrintAttributes;
44+
import android.print.PrintAttributes.MediaSize;
45+
import android.print.PrintDocumentAdapter;
46+
import android.print.PrintManager;
4347
import android.text.TextUtils;
4448
import android.util.Log;
4549
import androidx.annotation.NonNull;
50+
import androidx.fragment.app.FragmentActivity;
4651
import com.bumptech.glide.request.target.Target;
4752
import com.compdfkit.core.common.CPDFDocumentException;
4853
import com.compdfkit.core.document.CPDFDocument;
@@ -58,8 +63,10 @@
5863
import com.compdfkit.tools.common.utils.CFileUtils;
5964
import com.compdfkit.tools.common.utils.glide.GlideApp;
6065
import com.compdfkit.tools.common.utils.image.CBitmapUtil;
66+
import com.compdfkit.tools.common.utils.print.CPDFPrintUtils;
6167
import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
6268
import com.compdfkit.tools.common.utils.threadpools.SimpleBackgroundTask;
69+
import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
6370
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
6471
import com.compdfkit.ui.reader.CPDFReaderView;
6572
import io.flutter.plugin.common.BinaryMessenger;
@@ -75,6 +82,8 @@ public class CPDFDocumentPlugin extends BaseMethodChannelPlugin {
7582

7683
private CPDFViewCtrl pdfView;
7784

85+
private CPDFDocument document;
86+
7887
public CPDFDocumentPlugin(Context context,
7988
BinaryMessenger binaryMessenger, String documentUid) {
8089
super(context, binaryMessenger);
@@ -83,8 +92,12 @@ public CPDFDocumentPlugin(Context context,
8392

8493
public void setReaderView(CPDFViewCtrl pdfView) {
8594
this.pdfView = pdfView;
95+
this.document = pdfView.getCPdfReaderView().getPDFDocument();
8696
}
8797

98+
public void setDocument(CPDFDocument cpdfDocument) {
99+
this.document = cpdfDocument;
100+
}
88101

89102
@Override
90103
public String methodName() {
@@ -93,26 +106,55 @@ public String methodName() {
93106

94107
@Override
95108
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
96-
if (pdfView == null || pdfView.getCPdfReaderView().getPDFDocument() == null) {
109+
if (document == null) {
97110
result.error("-1", "CPDFReaderView isnull or CPDFDocument is null", null);
98111
return;
99112
}
100-
CPDFReaderView readerView = pdfView.getCPdfReaderView();
101-
CPDFDocument document = readerView.getPDFDocument();
102113
switch (call.method) {
103114
case OPEN_DOCUMENT:
104115
String filePath = call.argument("filePath");
105116
String openPwd = call.argument("password");
106117
PDFDocumentError error;
118+
Object object;
107119
if (filePath.startsWith(CONTENT_SCHEME) || filePath.startsWith(
108120
FileUtils.FILE_SCHEME)) {
109-
pdfView.openPDF(Uri.parse(filePath), openPwd, () -> {
110-
result.success(true);
111-
});
121+
object = Uri.parse(filePath);
122+
error = document.open(Uri.parse(filePath), openPwd);
112123
} else {
113-
pdfView.openPDF(filePath, openPwd, () -> {
114-
result.success(true);
115-
});
124+
object = filePath;
125+
error = document.open(filePath, openPwd);
126+
}
127+
switch (error){
128+
case PDFDocumentErrorSuccess:
129+
result.success("success");
130+
break;
131+
case PDFDocumentErrorPassword:
132+
result.success("errorPassword");
133+
break;
134+
case PDFDocumentErrorFile:
135+
result.success("errorFile");
136+
break;
137+
case PDFDocumentErrorPage:
138+
result.success("errorPage");
139+
break;
140+
case PDFDocumentErrorFormat:
141+
result.success("errorFormat");
142+
break;
143+
case PDFDocumentErrorUnknown:
144+
result.success("unknown");
145+
break;
146+
case PDFDocumentErrorSecurity:
147+
result.success("errorSecurity");
148+
break;
149+
case PDFDocumentNotVerifyLicense:
150+
result.success("notVerifyLicense");
151+
break;
152+
case PDFDocumentErrorNoReadPermission:
153+
result.success("noReadPermission");
154+
break;
155+
}
156+
if (error == PDFDocumentError.PDFDocumentErrorSuccess && pdfView != null){
157+
pdfView.setPDFDocument(document, object, error, null);
116158
}
117159
break;
118160
case GET_FILE_NAME:
@@ -159,7 +201,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
159201
cacheFile.mkdirs();
160202
boolean importResult = document.importAnnotations(xfdfFilePath,
161203
cacheFile.getAbsolutePath());
162-
readerView.reloadPages();
204+
if (pdfView != null) {
205+
pdfView.getCPdfReaderView().reloadPages();
206+
}
163207
result.success(importResult);
164208
} catch (Exception e) {
165209
e.printStackTrace();
@@ -190,8 +234,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
190234
break;
191235
case REMOVE_ALL_ANNOTATIONS:
192236
boolean deleteResult = document.removeAllAnnotations();
193-
if (deleteResult) {
194-
readerView.invalidateAllChildren();
237+
if (deleteResult && pdfView != null) {
238+
pdfView.getCPdfReaderView().invalidateAllChildren();
195239
}
196240
result.success(deleteResult);
197241
break;
@@ -211,6 +255,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
211255
String savePath = call.argument("save_path");
212256
boolean removeSecurity = call.argument("remove_security");
213257
boolean fontSubSet = call.argument("font_sub_set");
258+
if (pdfView != null){
259+
pdfView.exitEditMode();
260+
}
214261
CThreadPoolUtils.getInstance().executeIO(() -> {
215262
try {
216263
boolean saveResult;
@@ -219,10 +266,15 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
219266
} else {
220267
saveResult = document.saveAs(savePath, removeSecurity, false, fontSubSet);
221268
}
222-
if (document.shouleReloadDocument()) {
223-
document.reload();
224-
}
225-
result.success(saveResult);
269+
CThreadPoolUtils.getInstance().executeMain(()->{
270+
if (document.shouleReloadDocument()) {
271+
document.reload();
272+
if (pdfView != null) {
273+
pdfView.getCPdfReaderView().reloadPages();
274+
}
275+
}
276+
result.success(saveResult);
277+
});
226278
} catch (CPDFDocumentException e) {
227279
e.printStackTrace();
228280
result.error("SAVE_FAIL",
@@ -232,9 +284,10 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
232284
});
233285
break;
234286
case PRINT:
235-
String path = readerView.getPDFDocument().getAbsolutePath();
236-
Uri uri = readerView.getPDFDocument().getUri();
237-
CFileUtils.startPrint(context, path, uri);
287+
FragmentActivity fragmentActivity = CViewUtils.getFragmentActivity(pdfView.getContext());
288+
if (fragmentActivity != null){
289+
CPDFPrintUtils.printCurrentDocument(fragmentActivity, document);
290+
}
238291
break;
239292
case REMOVE_PASSWORD:
240293
CThreadPoolUtils.getInstance().executeIO(() -> {
@@ -326,16 +379,18 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
326379
}
327380
break;
328381
case CREATE_WATERMARK:
329-
Object object = call.arguments;
330-
Log.e("ComPDFKit-Flutter", "watermark:" + object.toString());
382+
Object watermarkObj = call.arguments;
383+
Log.e("ComPDFKit-Flutter", "watermark:" + watermarkObj.toString());
331384
createWatermark(call, result, pdfView, document);
332385
break;
333386
case REMOVE_ALL_WATERMARKS:
334387
for (int watermarkCount = document.getWatermarkCount(); watermarkCount > 0;
335388
watermarkCount--) {
336389
document.getWatermark(watermarkCount - 1).clear();
337390
}
338-
pdfView.getCPdfReaderView().reloadPages();
391+
if (pdfView != null) {
392+
pdfView.getCPdfReaderView().reloadPages();
393+
}
339394
break;
340395
default:
341396
break;

android/src/main/java/com/compdfkit/flutter/compdfkit_flutter/plugin/CPDFViewCtrlPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
263263
documentFragment.showBOTA();
264264
break;
265265
case SHOW_ADD_WATERMARK_VIEW:
266-
documentFragment.showAddWatermarkDialog();
266+
boolean saveAsNewFile = (boolean) call.arguments;
267+
documentFragment.showAddWatermarkDialog(saveAsNewFile);
267268
break;
268269
case SHOW_SECURITY_VIEW:
269270
documentFragment.showSecurityDialog();

android/src/main/java/com/compdfkit/flutter/compdfkit_flutter/plugin/ComPDFKitSDKPlugin.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package com.compdfkit.flutter.compdfkit_flutter.plugin;
1111

12+
import static com.compdfkit.flutter.compdfkit_flutter.constants.CPDFConstants.ChannelMethod.CREATE_DOCUMENT_PLUGIN;
1213
import static com.compdfkit.flutter.compdfkit_flutter.constants.CPDFConstants.ChannelMethod.CREATE_URI;
1314
import static com.compdfkit.flutter.compdfkit_flutter.constants.CPDFConstants.ChannelMethod.GET_TEMP_DIRECTORY;
1415
import static com.compdfkit.flutter.compdfkit_flutter.constants.CPDFConstants.ChannelMethod.INIT_SDK;
@@ -31,6 +32,7 @@
3132
import androidx.annotation.NonNull;
3233

3334
import androidx.annotation.Nullable;
35+
import com.compdfkit.core.document.CPDFDocument;
3436
import com.compdfkit.core.document.CPDFSdk;
3537
import com.compdfkit.core.font.CPDFFont;
3638
import com.compdfkit.flutter.compdfkit_flutter.utils.FileUtils;
@@ -135,6 +137,13 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
135137
CPDFSdk.setImportFontDir(importFontDir, addSysFont);
136138
result.success(true);
137139
break;
140+
case CREATE_DOCUMENT_PLUGIN:
141+
String id = (String) call.arguments;
142+
CPDFDocumentPlugin documentPlugin = new CPDFDocumentPlugin(context, binaryMessenger, id);
143+
documentPlugin.setDocument(new CPDFDocument(context));
144+
documentPlugin.register();
145+
result.success(true);
146+
break;
138147
default:
139148
break;
140149
}
@@ -145,13 +154,13 @@ public boolean onActivityResult(int requestCode, int resultCode, @Nullable Inten
145154
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK){
146155
if(data != null && data.getData() != null){
147156
Uri uri = data.getData();
157+
CFileUtils.takeUriPermission(context, uri);
148158
successResult(uri.toString());
149159
}
150160
return true;
151161
} else if (requestCode == REQUEST_CODE && resultCode != Activity.RESULT_OK){
152162
successResult(null);
153163
}
154-
155164
return false;
156165
}
157166

0 commit comments

Comments
 (0)