Skip to content

Commit d09a6ae

Browse files
author
PSPDFKit
committed
Release 3.2.0
1 parent 3519803 commit d09a6ae

File tree

16 files changed

+217
-21
lines changed

16 files changed

+217
-21
lines changed

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## Newest Release
22

3+
### 3.2.0 - 14 Feb 2022
4+
5+
- This release requires you to update your Android project's `compileSdkVersion` to version 31. Please refer to [our migration guide](https://pspdfkit.com/guides/flutter/migration-guides/flutter-3-2-0-migration-guide) for this release.
6+
- PSPDFKit now requires Flutter 2.10.1 or later. (#33016)
7+
- Adds a new configuration option to disable autosave. (#32857)
8+
- Adds a new example illustrating manual saving of documents with autosave disabled. (#32857)
9+
- Updates for PSPDFKit 8.1.1 for Android. (#33016)
10+
- Updates for PSPDFKit 11.2.2 for iOS. (#33016)
11+
12+
## Previous Releases
13+
314
### 3.1.0 - 06 Jan 2022
415

516
- Adds Flutter widget support for Android. (#23824)
@@ -24,8 +35,6 @@
2435
- Renames `pspdfkit_view.dart` into `pspdfkit_widget_controller.dart`. (#23824)
2536
- Fixes button overflow issue on iOS devices in the Flutter example. (#31198)
2637

27-
## Previous Releases
28-
2938
### 3.0.3 - 07 Dec 2021
3039

3140
- Updates for PSPDFKit 8.0.2 for Android. (#32165)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ If you are new to Flutter, make sure to check our Flutter blog posts:
1313
- [How to Customize Our Flutter PDF SDK for Android](https://pspdfkit.com/blog/2021/how-to-customize-our-flutter-pdf-sdk/).
1414
- [Advances in Hybrid Technologies](https://pspdfkit.com/blog/2019/advances-in-hybrid-technologies/).
1515
- [How We Maintain Our Public Flutter Project Using a Private Monorepo](https://pspdfkit.com/blog/2021/maintaining-open-source-repo-from-monorepo/).
16+
- [How to Download and Display a PDF Document in Flutter with PSPDFKit](https://pspdfkit.com/blog/2022/download-and-display-pdf-in-flutter-with-pspdfkit/).
1617

1718
For our quick-start guides, [check out our website](https://pspdfkit.com/getting-started/mobile/?frontend=flutter).
1819

android/config.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (pspdfkitMavenUrl == null || pspdfkitMavenUrl == '') {
3838

3939
ext.pspdfkitVersion = localProperties.getProperty('pspdfkit.version')
4040
if (pspdfkitVersion == null || pspdfkitVersion == '') {
41-
ext.pspdfkitVersion = '8.0.2'
41+
ext.pspdfkitVersion = '8.1.1'
4242
}
4343

4444
ext.pspdfkitMavenModuleName = 'pspdfkit'
@@ -52,9 +52,9 @@ if (!pubspecFile.exists()) {
5252
def pubspecYaml = new Yaml().load(pubspecFile.newInputStream())
5353
ext.pspdfkitFlutterVersion = pubspecYaml.version
5454

55-
ext.androidCompileSdkVersion = 30
55+
ext.androidCompileSdkVersion = 31
5656
ext.androidBuildToolsVersion = '30.0.3'
5757
ext.androidMinSdkVersion = 21
5858
ext.androidTargetSdkVersion = 30
59-
ext.androidGradlePluginVersion = '7.1.0-alpha03'
59+
ext.androidGradlePluginVersion = '7.1.1'
6060
ext.kotlinVersion = "1.5.31"

android/src/main/java/com/pspdfkit/flutter/pspdfkit/ConfigurationAdapter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class ConfigurationAdapter {
4040
private static final String SCROLL_DIRECTION = "scrollDirection";
4141
private static final String PAGE_TRANSITION = "pageTransition";
4242
private static final String ENABLE_TEXT_SELECTION = "enableTextSelection";
43-
43+
private static final String DISABLE_AUTOSAVE = "disableAutosave";
44+
45+
4446
// Document Presentation Options
4547
private static final String PAGE_MODE = "pageMode";
4648
private static final String SPREAD_FITTING = "spreadFitting";
@@ -342,6 +344,11 @@ class ConfigurationAdapter {
342344
if (key != null) {
343345
configureFirstPageAlwaysSingle((Boolean) configurationMap.get(key));
344346
}
347+
348+
key = getKeyOfType(configurationMap, DISABLE_AUTOSAVE, Boolean.class);
349+
if (key != null) {
350+
configureAutosaveEnabled(!(Boolean) configurationMap.get(key));
351+
}
345352
}
346353
}
347354

@@ -686,6 +693,10 @@ private void configureFirstPageAlwaysSingle(final boolean firstPageAlwaysSingle)
686693
configuration.firstPageAlwaysSingle(firstPageAlwaysSingle);
687694
}
688695

696+
private void configureAutosaveEnabled(boolean autosaveEnabled) {
697+
configuration.autosaveEnabled(autosaveEnabled);
698+
}
699+
689700
private <T> boolean containsKeyOfType(@NonNull HashMap<String, Object> configurationMap,
690701
@NonNull String key,
691702
@NonNull Class<T> clazz) {

android/src/main/java/com/pspdfkit/flutter/pspdfkit/PspdfkitPlugin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public class PspdfkitPlugin implements MethodCallHandler, PluginRegistry.Request
6464
FlutterPlugin, ActivityAware {
6565
@NonNull private static final EventDispatcher eventDispatcher = EventDispatcher.getInstance();
6666
private static final String LOG_TAG = "PSPDFKitPlugin";
67+
68+
/** Hybrid technology where the application is supposed to be working on. */
69+
private static final String HYBRID_TECHNOLOGY = "Flutter";
70+
6771
/** Atomic reference that prevents sending twice the permission result and throwing exception. */
6872
@NonNull private final AtomicReference<Result> permissionRequestResult;
6973

@@ -125,12 +129,12 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
125129
case "setLicenseKey":
126130
String licenseKey = call.argument("licenseKey");
127131
requireNotNullNotEmpty(licenseKey, "License key");
128-
PSPDFKit.initialize(activity, licenseKey);
132+
PSPDFKit.initialize(activity, licenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY);
129133
break;
130134
case "setLicenseKeys":
131135
String androidLicenseKey = call.argument("androidLicenseKey");
132136
requireNotNullNotEmpty(androidLicenseKey, "Android License key");
133-
PSPDFKit.initialize(activity, androidLicenseKey);
137+
PSPDFKit.initialize(activity, androidLicenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY);
134138
break;
135139
case "present":
136140
String documentPath = call.argument("document");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ flutter_ios_podfile_setup
2929

3030
target 'Runner' do
3131
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
32-
pod 'PSPDFKit', '~> 11.2.0'
32+
pod 'PSPDFKit', '~> 11.2.2'
3333
end
3434

3535
post_install do |installer|

example/lib/main.dart

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:pspdfkit_flutter/src/widgets/pspdfkit_widget.dart';
2020
import 'pspdfkit_form_example.dart';
2121
import 'pspdfkit_instantjson_example.dart';
2222
import 'pspdfkit_annotations_example.dart';
23+
import 'pspdfkit_manual_save_example.dart';
2324
import 'pspdfkit_annotation_processing_example.dart';
2425

2526
const String _documentPath = 'PDFs/PSPDFKit.pdf';
@@ -57,6 +58,9 @@ const String _annotationsExample =
5758
'Programmatically Adds and Removes Annotations';
5859
const String _annotationsExampleSub =
5960
'Programmatically adds and removes annotations using a custom Widget.';
61+
const String _manualSaveExample = 'Manual Save';
62+
const String _manualSaveExampleSub =
63+
'Add a save button at the bottom and disable automatic saving.';
6064
const String _annotationProcessingExample = 'Process Annotations';
6165
const String _annotationProcessingExampleSub =
6266
'Programmatically adds and removes annotations using a custom Widget.';
@@ -125,15 +129,19 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
125129
String _frameworkVersion = '';
126130
ThemeData currentTheme = lightTheme;
127131

128-
Future<File> extractAsset(String assetPath) async {
132+
Future<File> extractAsset(String assetPath,
133+
{bool shouldOverwrite = true, String prefix = ''}) async {
129134
final bytes = await DefaultAssetBundle.of(context).load(assetPath);
130135
final list = bytes.buffer.asUint8List();
131136

132137
final tempDir = await Pspdfkit.getTemporaryDirectory();
133-
final tempDocumentPath = '${tempDir.path}/$assetPath';
138+
final tempDocumentPath = '${tempDir.path}/$prefix$assetPath';
139+
final file = File(tempDocumentPath);
134140

135-
final file = await File(tempDocumentPath).create(recursive: true);
136-
file.writeAsBytesSync(list);
141+
if (shouldOverwrite || !file.existsSync()) {
142+
await file.create(recursive: true);
143+
file.writeAsBytesSync(list);
144+
}
137145
return file;
138146
}
139147

@@ -341,6 +349,18 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
341349
documentPath: extractedDocument.path)));
342350
}
343351

352+
void manualSaveExample() async {
353+
final extractedWritableDocument =
354+
await extractAsset(_documentPath, shouldOverwrite: false, prefix: 'persist');
355+
356+
// Automatic Saving of documents is enabled by default in certain scenarios [see for details: https://pspdfkit.com/guides/flutter/save-a-document/#auto-save]
357+
// In order to manually save documents, you might consider disabling automatic saving with disableAutosave: true in the config
358+
await Navigator.of(context).push<dynamic>(MaterialPageRoute<dynamic>(
359+
builder: (_) => PspdfkitManualSaveExampleWidget(
360+
documentPath: extractedWritableDocument.path,
361+
configuration: const {disableAutosave: true})));
362+
}
363+
344364
void annotationProcessingExample() async {
345365
final extractedDocument = await extractAsset(_documentPath);
346366
await Navigator.of(context).push<dynamic>(MaterialPageRoute<dynamic>(
@@ -645,6 +665,10 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
645665
title: const Text(_annotationsExample),
646666
subtitle: const Text(_annotationsExampleSub),
647667
onTap: () => annotationsExample()),
668+
ListTile(
669+
title: const Text(_manualSaveExample),
670+
subtitle: const Text(_manualSaveExampleSub),
671+
onTap: () => manualSaveExample()),
648672
// The annotation processing example is supported by iOS only for now.
649673
if (isCupertino(context))
650674
ListTile(

example/lib/platform_utils.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:flutter/foundation.dart';
2+
3+
class PlatformUtils {
4+
static bool isCurrentPlatformSupported() {
5+
return defaultTargetPlatform == TargetPlatform.android ||
6+
defaultTargetPlatform == TargetPlatform.iOS;
7+
}
8+
9+
static bool isAndroid() {
10+
return defaultTargetPlatform == TargetPlatform.android;
11+
}
12+
13+
static bool isIOS() {
14+
return defaultTargetPlatform == TargetPlatform.iOS;
15+
}
16+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
///
2+
/// Copyright © 2022 PSPDFKit GmbH. All rights reserved.
3+
///
4+
/// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
/// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
/// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
/// This notice may not be removed from this file.
8+
///
9+
10+
import 'dart:async';
11+
12+
import 'package:flutter/services.dart';
13+
import 'package:flutter/foundation.dart';
14+
import 'package:flutter/gestures.dart';
15+
import 'package:flutter/rendering.dart';
16+
import 'package:flutter/cupertino.dart';
17+
import 'package:flutter/material.dart';
18+
19+
import 'package:pspdfkit_flutter/src/widgets/pspdfkit_widget_controller.dart';
20+
21+
import 'platform_utils.dart';
22+
23+
class PspdfkitManualSaveExampleWidget extends StatefulWidget {
24+
final String documentPath;
25+
final dynamic configuration;
26+
27+
const PspdfkitManualSaveExampleWidget(
28+
{Key? key, required this.documentPath, this.configuration})
29+
: super(key: key);
30+
31+
@override
32+
_PspdfkitManualSaveExampleWidgetState createState() =>
33+
_PspdfkitManualSaveExampleWidgetState();
34+
}
35+
36+
class _PspdfkitManualSaveExampleWidgetState
37+
extends State<PspdfkitManualSaveExampleWidget> {
38+
late PspdfkitWidgetController pspdfkitWidgetController;
39+
40+
@override
41+
Widget build(BuildContext context) {
42+
// This is used in the platform side to register the view.
43+
const String viewType = 'com.pspdfkit.widget';
44+
// Pass parameters to the platform side.
45+
final Map<String, dynamic> creationParams = <String, dynamic>{
46+
'document': widget.documentPath,
47+
'configuration': widget.configuration
48+
};
49+
if (PlatformUtils.isCurrentPlatformSupported()) {
50+
return Scaffold(
51+
extendBodyBehindAppBar:
52+
defaultTargetPlatform == TargetPlatform.android,
53+
appBar: AppBar(),
54+
body: SafeArea(
55+
top: false,
56+
bottom: false,
57+
child: Container(
58+
padding: defaultTargetPlatform == TargetPlatform.iOS
59+
? null
60+
: const EdgeInsets.only(top: kToolbarHeight),
61+
child: Column(children: <Widget>[
62+
Expanded(
63+
child: PlatformUtils.isAndroid()
64+
? PlatformViewLink(
65+
viewType: viewType,
66+
surfaceFactory: (BuildContext context,
67+
PlatformViewController controller) {
68+
return AndroidViewSurface(
69+
controller:
70+
controller as AndroidViewController,
71+
gestureRecognizers: const <
72+
Factory<
73+
OneSequenceGestureRecognizer>>{},
74+
hitTestBehavior:
75+
PlatformViewHitTestBehavior.opaque,
76+
);
77+
},
78+
onCreatePlatformView:
79+
(PlatformViewCreationParams params) {
80+
return PlatformViewsService
81+
.initSurfaceAndroidView(
82+
id: params.id,
83+
viewType: viewType,
84+
layoutDirection: TextDirection.ltr,
85+
creationParams: creationParams,
86+
creationParamsCodec:
87+
const StandardMessageCodec(),
88+
onFocus: () {
89+
params.onFocusChanged(true);
90+
},
91+
)
92+
..addOnPlatformViewCreatedListener(
93+
params.onPlatformViewCreated)
94+
..addOnPlatformViewCreatedListener(
95+
onPlatformViewCreated)
96+
..create();
97+
})
98+
: UiKitView(
99+
viewType: viewType,
100+
layoutDirection: TextDirection.ltr,
101+
creationParams: creationParams,
102+
onPlatformViewCreated: onPlatformViewCreated,
103+
creationParamsCodec:
104+
const StandardMessageCodec())),
105+
SizedBox(
106+
child: Column(children: <Widget>[
107+
ElevatedButton(
108+
onPressed: () async {
109+
await pspdfkitWidgetController.save();
110+
},
111+
child: const Text('Save Document'))
112+
]))
113+
]))));
114+
} else {
115+
return Text(
116+
'$defaultTargetPlatform is not yet supported by PSPDFKit for Flutter.');
117+
}
118+
}
119+
120+
Future<void> onPlatformViewCreated(int id) async {
121+
pspdfkitWidgetController = PspdfkitWidgetController(id);
122+
}
123+
}

0 commit comments

Comments
 (0)