Skip to content

Commit 0dfa3c0

Browse files
committed
Merge branch 'development'
2 parents 6b78186 + 3b5198f commit 0dfa3c0

File tree

8 files changed

+117
-11
lines changed

8 files changed

+117
-11
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.0.5
2+
3+
* Bumped Android to 4.0.8
4+
* Bumped iOS to 2.0.6
5+
* Added method `purge()`.
6+
* Added setup options `PerformOnDeviceOCR` and `OutputFormat`.
7+
18
## 1.0.4
29

310
* Bumped Android to 4.0.6

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ config.userShouldAcceptResultToContinue = false;
213213
// What the default color conversion will be (grayscale, original, enhanced).
214214
config.defaultColor = DefaultColor.original;
215215
216+
/// Whether to perform on-device OCR after scanning completes.
217+
config.performOnDeviceOCR = false;
218+
219+
/// What the output format will be (jpeg, pdfMerged, pdfSingle). (Default jpeg)
220+
config.outputFormat = OutputFormat.jpeg;
221+
216222
// Enable Single Document Mode
217223
config.cameraModeSingle = new CameraMode();
218224
// Localize the name of Single Document Mode
@@ -438,6 +444,19 @@ config.cameraModeMulti?.image = "{name of image in Assets.xcassets}";
438444
config.cameraModeSingle?.image = "{name of image in Assets.xcassets}";
439445
```
440446

447+
## How to clear the storage.
448+
449+
```dart
450+
import 'package:klippa_scanner_sdk/klippa_scanner_sdk.dart';
451+
452+
try {
453+
await KlippaScannerSdk.purge();
454+
} on PlatformException catch (e) {
455+
print('Failed to purge storage: ' + e.toString());
456+
}
457+
```
458+
459+
441460
## Important iOS notes
442461
Older iOS versions do not ship the Swift libraries. To make sure the SDK works on older iOS versions, you can configure the build to embed the Swift libraries using the build setting `EMBEDDED_CONTENT_CONTAINS_SWIFT = YES`.
443462

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ android {
7777
}
7878

7979
dependencies {
80-
def fallbackKlippaScannerVersion = "4.0.6"
80+
def fallbackKlippaScannerVersion = "4.0.8"
8181
def klippaScannerVersion = project.hasProperty('klippaScannerVersion') ? project.klippaScannerVersion : fallbackKlippaScannerVersion
8282
implementation "com.klippa:scanner:$klippaScannerVersion"
8383
}

android/src/main/kotlin/com/klippa/scanner/klippa_scanner_sdk/KlippaScannerSdkPlugin.kt

+35-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import com.klippa.scanner.model.KlippaError
1313
import com.klippa.scanner.model.KlippaImageColor
1414
import com.klippa.scanner.model.KlippaMultipleDocumentMode
1515
import com.klippa.scanner.model.KlippaObjectDetectionModel
16+
import com.klippa.scanner.model.KlippaOutputFormat
1617
import com.klippa.scanner.model.KlippaScannerResult
1718
import com.klippa.scanner.model.KlippaSegmentedDocumentMode
1819
import com.klippa.scanner.model.KlippaSingleDocumentMode
1920
import com.klippa.scanner.model.KlippaSize
21+
import com.klippa.scanner.storage.KlippaStorage
2022
import io.flutter.embedding.engine.plugins.FlutterPlugin
2123
import io.flutter.embedding.engine.plugins.activity.ActivityAware
2224
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
@@ -72,13 +74,23 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
7274
}
7375

7476
override fun onMethodCall(call: MethodCall, result: Result) {
75-
if (call.method == "startSession") {
76-
startSession(call, result)
77-
} else {
78-
result.notImplemented()
77+
when (call.method) {
78+
"startSession" -> startSession(call, result)
79+
"purge" -> purge(result)
80+
else -> result.notImplemented()
7981
}
8082
}
8183

84+
private fun purge(result: Result) {
85+
val activity = activityPluginBinding?.activity ?: kotlin.run {
86+
result.error(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist", null)
87+
return
88+
}
89+
90+
KlippaStorage.purge(activity)
91+
result.success(null)
92+
}
93+
8294
private fun startSession(call: MethodCall, result: Result) {
8395
val activity = activityPluginBinding?.activity ?: kotlin.run {
8496
result.error(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist", null)
@@ -172,6 +184,20 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
172184
}
173185
}
174186

187+
call.argument<String>("OutputFormat")?.let {
188+
when (it) {
189+
"jpeg" -> {
190+
scannerSession.imageAttributes.outputFormat = KlippaOutputFormat.JPEG
191+
}
192+
"pdfSingle" -> {
193+
scannerSession.imageAttributes.outputFormat = KlippaOutputFormat.PDF_SINGLE
194+
}
195+
"pdfMerged" -> {
196+
scannerSession.imageAttributes.outputFormat = KlippaOutputFormat.PDF_MERGED
197+
}
198+
}
199+
}
200+
175201
call.argument<Int>("ImageLimit")?.let {
176202
scannerSession.imageAttributes.imageLimit = it
177203
}
@@ -184,6 +210,10 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
184210
scannerSession.imageAttributes.imageMovingSensitivity = it
185211
}
186212

213+
call.argument<Boolean>("PerformOnDeviceOCR")?.let {
214+
scannerSession.imageAttributes.performOnDeviceOCR = it
215+
}
216+
187217
call.argument<Boolean>("StoreImagesToCameraRoll")?.let {
188218
scannerSession.imageAttributes.storeImagesToGallery = it
189219
}
@@ -322,7 +352,7 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
322352
private fun klippaScannerDidFinishScanningWithResult(result: KlippaScannerResult) {
323353
val images: MutableList<Map<String, String>> = mutableListOf()
324354

325-
for (image in result.images) {
355+
for (image in result.results) {
326356
val imageDict = mapOf("Filepath" to image.location)
327357
images.add(imageDict)
328358
}

ios/Classes/SwiftKlippaScannerSdkPlugin.swift

+29-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, KlippaScanner
1616
}
1717

1818
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
19-
if call.method == "startSession" {
19+
switch call.method {
20+
case "startSession":
2021
startSession(call, result: result)
21-
} else {
22+
case "purge":
23+
purge(result: result)
24+
default:
2225
result(FlutterMethodNotImplemented)
2326
}
2427
}
2528

29+
private func purge(result: @escaping FlutterResult) {
30+
KlippaScannerStorage.purge()
31+
result(nil)
32+
}
33+
2634
private func startSession(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
2735
guard let args = call.arguments else {
2836
result(FlutterError.init(code: E_UNKNOWN_ERROR, message: "Unknown error", details: nil))
@@ -271,6 +279,24 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, KlippaScanner
271279
builder.klippaMenu.shouldGoToReviewScreenOnFinishPressed = shouldGoToReviewScreenOnFinishPressed
272280
}
273281

282+
283+
if let outputFormat = builderArgs?["OutputFormat"] as? String {
284+
switch outputFormat {
285+
case "jpeg":
286+
builder.klippaImageAttributes.outputFormat = .jpeg
287+
case "pdfSingle":
288+
builder.klippaImageAttributes.outputFormat = .pdfSingle
289+
case "pdfMerged":
290+
builder.klippaImageAttributes.outputFormat = .pdfMerged
291+
default:
292+
builder.klippaImageAttributes.outputFormat = .jpeg
293+
}
294+
}
295+
296+
if let performOnDeviceOCR = builderArgs?["PerformOnDeviceOCR"] as? Bool {
297+
builder.klippaImageAttributes.performOnDeviceOCR = performOnDeviceOCR
298+
}
299+
274300
if let brightnessLowerThreshold = builderArgs?["BrightnessLowerThreshold"] as? Double {
275301
builder.klippaImageAttributes.brightnessLowerThreshold = brightnessLowerThreshold
276302
}
@@ -382,7 +408,7 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, KlippaScanner
382408

383409
public func klippaScannerDidFinishScanningWithResult(result: KlippaScannerResult) {
384410
var images: [[String: String]] = []
385-
for image in result.images {
411+
for image in result.results {
386412
let imageDict = ["Filepath" : image.path]
387413
images.append(imageDict)
388414
}

ios/sdk_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.5
1+
2.0.6

lib/klippa_scanner_sdk.dart

+24
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class CameraMode {
5858
String? image;
5959
}
6060

61+
enum OutputFormat {
62+
jpeg,
63+
pdfSingle,
64+
pdfMerged
65+
}
66+
6167
class CameraConfig {
6268
/// Global options.
6369
@@ -142,6 +148,12 @@ class CameraConfig {
142148
/// Whether the camera automatically saves the images to the camera roll (iOS) / gallery (Android). Default true.
143149
bool? storeImagesToCameraRol;
144150

151+
/// Whether to perform on-device OCR after scanning completes.
152+
bool? performOnDeviceOCR;
153+
154+
/// What the output format will be (jpeg, pdfMerged, pdfSingle). (Default jpeg)
155+
OutputFormat? outputFormat;
156+
145157
/// The camera mode for scanning one part documents.
146158
CameraMode? cameraModeSingle;
147159

@@ -271,6 +283,10 @@ class KlippaScannerSdk {
271283
static const MethodChannel _channel =
272284
const MethodChannel('klippa_scanner_sdk');
273285

286+
static Future<void> purge() async {
287+
return await _channel.invokeMethod('purge');
288+
}
289+
274290
static Future<Map> startSession(
275291
final CameraConfig config, String license) async {
276292
Map<String, dynamic> parameters = {};
@@ -347,6 +363,14 @@ class KlippaScannerSdk {
347363
parameters["StoreImagesToCameraRoll"] = config.storeImagesToCameraRol;
348364
}
349365

366+
if (config.performOnDeviceOCR != null) {
367+
parameters["PerformOnDeviceOCR"] = config.performOnDeviceOCR;
368+
}
369+
370+
if (config.outputFormat != null) {
371+
parameters["OutputFormat"] = config.outputFormat;
372+
}
373+
350374
if (config.cameraModeSingle != null) {
351375
parameters["CameraModeSingle"] = {
352376
'name': config.cameraModeSingle?.name,

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: klippa_scanner_sdk
22
description: Allows you to do document scanning with the Klippa Scanner SDK from Flutter apps.
3-
version: 1.0.4
3+
version: 1.0.5
44
homepage: https://github.com/klippa-app/flutter-klippa-scanner-sdk
55

66
environment:

0 commit comments

Comments
 (0)