Skip to content

Commit

Permalink
Release 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PSPDFKit committed Feb 22, 2022
1 parent 3519803 commit d09a6ae
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 21 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## Newest Release

### 3.2.0 - 14 Feb 2022

- 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.
- PSPDFKit now requires Flutter 2.10.1 or later. (#33016)
- Adds a new configuration option to disable autosave. (#32857)
- Adds a new example illustrating manual saving of documents with autosave disabled. (#32857)
- Updates for PSPDFKit 8.1.1 for Android. (#33016)
- Updates for PSPDFKit 11.2.2 for iOS. (#33016)

## Previous Releases

### 3.1.0 - 06 Jan 2022

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

## Previous Releases

### 3.0.3 - 07 Dec 2021

- Updates for PSPDFKit 8.0.2 for Android. (#32165)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you are new to Flutter, make sure to check our Flutter blog posts:
- [How to Customize Our Flutter PDF SDK for Android](https://pspdfkit.com/blog/2021/how-to-customize-our-flutter-pdf-sdk/).
- [Advances in Hybrid Technologies](https://pspdfkit.com/blog/2019/advances-in-hybrid-technologies/).
- [How We Maintain Our Public Flutter Project Using a Private Monorepo](https://pspdfkit.com/blog/2021/maintaining-open-source-repo-from-monorepo/).
- [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/).

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

Expand Down
6 changes: 3 additions & 3 deletions android/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (pspdfkitMavenUrl == null || pspdfkitMavenUrl == '') {

ext.pspdfkitVersion = localProperties.getProperty('pspdfkit.version')
if (pspdfkitVersion == null || pspdfkitVersion == '') {
ext.pspdfkitVersion = '8.0.2'
ext.pspdfkitVersion = '8.1.1'
}

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

ext.androidCompileSdkVersion = 30
ext.androidCompileSdkVersion = 31
ext.androidBuildToolsVersion = '30.0.3'
ext.androidMinSdkVersion = 21
ext.androidTargetSdkVersion = 30
ext.androidGradlePluginVersion = '7.1.0-alpha03'
ext.androidGradlePluginVersion = '7.1.1'
ext.kotlinVersion = "1.5.31"
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class ConfigurationAdapter {
private static final String SCROLL_DIRECTION = "scrollDirection";
private static final String PAGE_TRANSITION = "pageTransition";
private static final String ENABLE_TEXT_SELECTION = "enableTextSelection";

private static final String DISABLE_AUTOSAVE = "disableAutosave";


// Document Presentation Options
private static final String PAGE_MODE = "pageMode";
private static final String SPREAD_FITTING = "spreadFitting";
Expand Down Expand Up @@ -342,6 +344,11 @@ class ConfigurationAdapter {
if (key != null) {
configureFirstPageAlwaysSingle((Boolean) configurationMap.get(key));
}

key = getKeyOfType(configurationMap, DISABLE_AUTOSAVE, Boolean.class);
if (key != null) {
configureAutosaveEnabled(!(Boolean) configurationMap.get(key));
}
}
}

Expand Down Expand Up @@ -686,6 +693,10 @@ private void configureFirstPageAlwaysSingle(final boolean firstPageAlwaysSingle)
configuration.firstPageAlwaysSingle(firstPageAlwaysSingle);
}

private void configureAutosaveEnabled(boolean autosaveEnabled) {
configuration.autosaveEnabled(autosaveEnabled);
}

private <T> boolean containsKeyOfType(@NonNull HashMap<String, Object> configurationMap,
@NonNull String key,
@NonNull Class<T> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public class PspdfkitPlugin implements MethodCallHandler, PluginRegistry.Request
FlutterPlugin, ActivityAware {
@NonNull private static final EventDispatcher eventDispatcher = EventDispatcher.getInstance();
private static final String LOG_TAG = "PSPDFKitPlugin";

/** Hybrid technology where the application is supposed to be working on. */
private static final String HYBRID_TECHNOLOGY = "Flutter";

/** Atomic reference that prevents sending twice the permission result and throwing exception. */
@NonNull private final AtomicReference<Result> permissionRequestResult;

Expand Down Expand Up @@ -125,12 +129,12 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "setLicenseKey":
String licenseKey = call.argument("licenseKey");
requireNotNullNotEmpty(licenseKey, "License key");
PSPDFKit.initialize(activity, licenseKey);
PSPDFKit.initialize(activity, licenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY);
break;
case "setLicenseKeys":
String androidLicenseKey = call.argument("androidLicenseKey");
requireNotNullNotEmpty(androidLicenseKey, "Android License key");
PSPDFKit.initialize(activity, androidLicenseKey);
PSPDFKit.initialize(activity, androidLicenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY);
break;
case "present":
String documentPath = call.argument("document");
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ flutter_ios_podfile_setup

target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
pod 'PSPDFKit', '~> 11.2.0'
pod 'PSPDFKit', '~> 11.2.2'
end

post_install do |installer|
Expand Down
32 changes: 28 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:pspdfkit_flutter/src/widgets/pspdfkit_widget.dart';
import 'pspdfkit_form_example.dart';
import 'pspdfkit_instantjson_example.dart';
import 'pspdfkit_annotations_example.dart';
import 'pspdfkit_manual_save_example.dart';
import 'pspdfkit_annotation_processing_example.dart';

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

Future<File> extractAsset(String assetPath) async {
Future<File> extractAsset(String assetPath,
{bool shouldOverwrite = true, String prefix = ''}) async {
final bytes = await DefaultAssetBundle.of(context).load(assetPath);
final list = bytes.buffer.asUint8List();

final tempDir = await Pspdfkit.getTemporaryDirectory();
final tempDocumentPath = '${tempDir.path}/$assetPath';
final tempDocumentPath = '${tempDir.path}/$prefix$assetPath';
final file = File(tempDocumentPath);

final file = await File(tempDocumentPath).create(recursive: true);
file.writeAsBytesSync(list);
if (shouldOverwrite || !file.existsSync()) {
await file.create(recursive: true);
file.writeAsBytesSync(list);
}
return file;
}

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

void manualSaveExample() async {
final extractedWritableDocument =
await extractAsset(_documentPath, shouldOverwrite: false, prefix: 'persist');

// Automatic Saving of documents is enabled by default in certain scenarios [see for details: https://pspdfkit.com/guides/flutter/save-a-document/#auto-save]
// In order to manually save documents, you might consider disabling automatic saving with disableAutosave: true in the config
await Navigator.of(context).push<dynamic>(MaterialPageRoute<dynamic>(
builder: (_) => PspdfkitManualSaveExampleWidget(
documentPath: extractedWritableDocument.path,
configuration: const {disableAutosave: true})));
}

void annotationProcessingExample() async {
final extractedDocument = await extractAsset(_documentPath);
await Navigator.of(context).push<dynamic>(MaterialPageRoute<dynamic>(
Expand Down Expand Up @@ -645,6 +665,10 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
title: const Text(_annotationsExample),
subtitle: const Text(_annotationsExampleSub),
onTap: () => annotationsExample()),
ListTile(
title: const Text(_manualSaveExample),
subtitle: const Text(_manualSaveExampleSub),
onTap: () => manualSaveExample()),
// The annotation processing example is supported by iOS only for now.
if (isCupertino(context))
ListTile(
Expand Down
16 changes: 16 additions & 0 deletions example/lib/platform_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/foundation.dart';

class PlatformUtils {
static bool isCurrentPlatformSupported() {
return defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS;
}

static bool isAndroid() {
return defaultTargetPlatform == TargetPlatform.android;
}

static bool isIOS() {
return defaultTargetPlatform == TargetPlatform.iOS;
}
}
123 changes: 123 additions & 0 deletions example/lib/pspdfkit_manual_save_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
///
/// Copyright © 2022 PSPDFKit GmbH. 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 PSPDFKIT LICENSE AGREEMENT.
/// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
/// This notice may not be removed from this file.
///
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:pspdfkit_flutter/src/widgets/pspdfkit_widget_controller.dart';

import 'platform_utils.dart';

class PspdfkitManualSaveExampleWidget extends StatefulWidget {
final String documentPath;
final dynamic configuration;

const PspdfkitManualSaveExampleWidget(
{Key? key, required this.documentPath, this.configuration})
: super(key: key);

@override
_PspdfkitManualSaveExampleWidgetState createState() =>
_PspdfkitManualSaveExampleWidgetState();
}

class _PspdfkitManualSaveExampleWidgetState
extends State<PspdfkitManualSaveExampleWidget> {
late PspdfkitWidgetController pspdfkitWidgetController;

@override
Widget build(BuildContext context) {
// This is used in the platform side to register the view.
const String viewType = 'com.pspdfkit.widget';
// Pass parameters to the platform side.
final Map<String, dynamic> creationParams = <String, dynamic>{
'document': widget.documentPath,
'configuration': widget.configuration
};
if (PlatformUtils.isCurrentPlatformSupported()) {
return Scaffold(
extendBodyBehindAppBar:
defaultTargetPlatform == TargetPlatform.android,
appBar: AppBar(),
body: SafeArea(
top: false,
bottom: false,
child: Container(
padding: defaultTargetPlatform == TargetPlatform.iOS
? null
: const EdgeInsets.only(top: kToolbarHeight),
child: Column(children: <Widget>[
Expanded(
child: PlatformUtils.isAndroid()
? PlatformViewLink(
viewType: viewType,
surfaceFactory: (BuildContext context,
PlatformViewController controller) {
return AndroidViewSurface(
controller:
controller as AndroidViewController,
gestureRecognizers: const <
Factory<
OneSequenceGestureRecognizer>>{},
hitTestBehavior:
PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView:
(PlatformViewCreationParams params) {
return PlatformViewsService
.initSurfaceAndroidView(
id: params.id,
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec:
const StandardMessageCodec(),
onFocus: () {
params.onFocusChanged(true);
},
)
..addOnPlatformViewCreatedListener(
params.onPlatformViewCreated)
..addOnPlatformViewCreatedListener(
onPlatformViewCreated)
..create();
})
: UiKitView(
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
onPlatformViewCreated: onPlatformViewCreated,
creationParamsCodec:
const StandardMessageCodec())),
SizedBox(
child: Column(children: <Widget>[
ElevatedButton(
onPressed: () async {
await pspdfkitWidgetController.save();
},
child: const Text('Save Document'))
]))
]))));
} else {
return Text(
'$defaultTargetPlatform is not yet supported by PSPDFKit for Flutter.');
}
}

Future<void> onPlatformViewCreated(int id) async {
pspdfkitWidgetController = PspdfkitWidgetController(id);
}
}
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: pspdfkit_example
description: Demonstrates how to use the pspdfkit plugin.
version: 3.1.0
version: 3.2.0
homepage: https://pspdfkit.com/
environment:
sdk: '>=2.12.0 <3.0.0'
flutter: '>=2.8.1'
flutter: '>=2.10.1'

dependencies:
flutter:
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/PspdfkitFlutterConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ + (PSPDFConfiguration *)configuration:(NSDictionary *)dictionary isImageDocument
builder.showForwardActionButton = [dictionary[key] boolValue];
builder.showBackForwardActionButtonLabels = [dictionary[key] boolValue];
}

key = @"disableAutosave";
if (dictionary[key]){
builder.autosaveEnabled = ![dictionary[key] boolValue];
}
}];
}

Expand Down
6 changes: 4 additions & 2 deletions ios/Classes/PspdfkitPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ @interface PspdfkitPlugin() <PSPDFViewControllerDelegate>

@implementation PspdfkitPlugin

PSPDFSettingKey const PSPDFSettingKeyHybridEnvironment = @"com.pspdfkit.hybrid-environment";

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
PspdfPlatformViewFactory *platformViewFactory = [[PspdfPlatformViewFactory alloc] initWithMessenger:[registrar messenger]];
[registrar registerViewFactory:platformViewFactory withId:@"com.pspdfkit.widget"];
Expand All @@ -36,10 +38,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
result([@"iOS " stringByAppendingString:PSPDFKitGlobal.versionNumber]);
} else if ([@"setLicenseKey" isEqualToString:call.method]) {
NSString *licenseKey = call.arguments[@"licenseKey"];
[PSPDFKitGlobal setLicenseKey:licenseKey];
[PSPDFKitGlobal setLicenseKey:licenseKey options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}];
} else if ([@"setLicenseKeys" isEqualToString:call.method]) {
NSString *iOSLicenseKey = call.arguments[@"iOSLicenseKey"];
[PSPDFKitGlobal setLicenseKey:iOSLicenseKey];
[PSPDFKitGlobal setLicenseKey:iOSLicenseKey options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}];
}else if ([@"present" isEqualToString:call.method]) {
NSString *documentPath = call.arguments[@"document"];

Expand Down
2 changes: 1 addition & 1 deletion ios/pspdfkit_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'pspdfkit_flutter'
s.version = '3.1.0'
s.version = '3.2.0'
s.homepage = 'https://PSPDFKit.com'
s.documentation_url = 'https://pspdfkit.com/guides/flutter'
s.license = { :type => 'Commercial', :file => '../LICENSE' }
Expand Down
Loading

0 comments on commit d09a6ae

Please sign in to comment.