Skip to content

Commit cf2375b

Browse files
author
PSPDFKit
committed
Release 3.12.0
1 parent a7cc9f5 commit cf2375b

35 files changed

+722
-91
lines changed

ACKNOWLEDGEMENTS.md

+26
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,32 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
38703870
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
38713871
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38723872

3873+
--------------------------------------------------------------------------------
3874+
## swift-perception (https://github.com/pointfreeco/swift-perception)
3875+
3876+
MIT License
3877+
3878+
Copyright (c) 2023 Point-Free
3879+
3880+
Permission is hereby granted, free of charge, to any person obtaining a copy
3881+
of this software and associated documentation files (the "Software"), to deal
3882+
in the Software without restriction, including without limitation the rights
3883+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3884+
copies of the Software, and to permit persons to whom the Software is
3885+
furnished to do so, subject to the following conditions:
3886+
3887+
The above copyright notice and this permission notice shall be included in all
3888+
copies or substantial portions of the Software.
3889+
3890+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3891+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3892+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3893+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3894+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3895+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3896+
SOFTWARE.
3897+
3898+
38733899
--------------------------------------------------------------------------------
38743900
## Tesseract (https://tesseract-ocr.github.io/)
38753901

CHANGELOG.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
## Newest Release
22

3+
### 3.12.0 - 30 Jul 2024
4+
5+
- Adds `zoomToRect` and `getVisibleRect` APIs to PspdfkitWidgetController. (J#HYB-429)
6+
- Added `processAnnotations` API support for Android. (J#HYB-426)
7+
- Updated the `processAnnotations` parameter types to enums `AnnotationType` and `AnnotationProcessingMode`. (#44722)
8+
- Updates for PSPDFKit 2024.4.0 for Android. (J#HYB-422)
9+
- Updates for PSPDFKit 13.8.0 for iOS. (J#HYB-422)
10+
11+
## Previous Releases
12+
313
### 3.11.0 - 21 Jun 2024
14+
415
- Adds API to get form filed properties to PdfDocument. (J#HYB-169)
516
- Adds instant synchronization support on Web. (J#HYB-377)
617

7-
## Previous Releases
8-
918
### 3.10.1 - 28 May 2024
19+
1020
- Fixes issue where ViewUtils.generateViewId() cannot be resolved. (J#HYB-379)
1121

1222
### 3.10.0 - 03 May 2024
23+
1324
- Adds APIs to get page information such as size, rotation, and label. (J#HYB-195)
1425
- Adds document load callbacks to `PspdfkitWidget`. (J#HYB-195)
1526
- Adds page change callback to `PspdfkitWidget`. (J#HYB-195)
@@ -18,6 +29,7 @@
1829
- Updates for PSPDFKit 13.4.1 for iOS.
1930

2031
### 3.9.1 - 12 Apr 2024
32+
2133
- Downgrades to AGP 7.* for backward compatibility (J#HYB-290)
2234
- Allow null value for `Pspdfkit.setLicenseKey` (J#HYB-294)
2335
- Updates for PSPDFKit 2024.2.1 for Android (J#HYB-303)
@@ -38,9 +50,11 @@
3850
- Fixes issue where annotation toolbar items are not being displayed on Web. (J#HYB-217)
3951

4052
### 3.8.1 - 14 Feb 2024
53+
4154
- Fixes callbacks when Pspdfkit.present() is used. (J#HYB-204)
4255

4356
### 3.8.0 - 06 Feb 2024
57+
4458
- Adds Flutter for Web support. (#42151)
4559
- Replaces configuration `Map` with a dedicated `PdfConfiguration` class. (#42191)
4660
- Deprecates imports for `package:pspdfkit_flutter/widgets/pspdfkit_widget.dart` and `package:pspdfkit_flutter/widgets/pspdfkit_widget_controller.dart`.
@@ -68,17 +82,20 @@
6882
- Updates example catalog with PspdfkitWidget usage. (#40861)
6983

7084
### 3.6.0 - 08 May 2023
85+
7186
- Adds measurement tools. (#39806)
7287
- Updates for PSPDFKit 8.6.0 for Android. (#39501)
7388
- Updates for PSPDFKit 12.2 for iOS. (#39995)
7489

7590
### 3.5.1 - 15 Mar 2023
91+
7692
- Updates iOS license initialization in the example catalog. (#38999)
7793
- Updates Instant web demo links. (#39018)
7894
- Updates for PSPDFKit 8.5.1 for Android. (#39090)
7995
- Updates for PSPDFKit 12.1.2 for iOS. (#39090)
8096

8197
### 3.5.0 - 17 Jan 2023
98+
8299
- Adds Instant Synchronization support. (#37675)
83100
- Updates for PSPDFKit 8.5 for Android. (#38136)
84101
- Updates for PSPDFKit 12.0.2 for iOS. (#38136)

android/config.gradle

+1-1
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 = '2024.3.0'
41+
ext.pspdfkitVersion = '2024.4.0'
4242
}
4343

4444
ext.pspdfkitMavenModuleName = 'pspdfkit'

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ class ConfigurationAdapter {
188188
private static final String ENABLED_MEASUREMENT_TOOLS = "enableMeasurementTools";
189189
private static final String ENABLE_MAGNIFIER = "enableMagnifier";
190190
private static final String ENABLED_MEASUREMENT_TOOL_SNAPPING = "enableMeasurementToolSnapping";
191-
191+
private static final String MAXIMUM_ZOOM_SCALE = "maximumZoomScale";
192+
private static final String MINIMUM_ZOOM_SCALE = "minimumZoomScale";
193+
private static final String DEFAULT_ZOOM_SCALE = "defaultZoomScale";
194+
192195
@NonNull
193196
private final PdfActivityConfiguration.Builder configuration;
194197
@Nullable
@@ -386,6 +389,17 @@ class ConfigurationAdapter {
386389
if (key != null) {
387390
configureMeasurementToolSnappingEnabled(context,(Boolean) configurationMap.get(key));
388391
}
392+
393+
key = getKeyOfType(configurationMap, MAXIMUM_ZOOM_SCALE, Double.class);
394+
if (key != null) {
395+
configuration.maxZoomScale((float) configurationMap.get(key));
396+
}
397+
398+
key = getKeyOfType(configurationMap, DEFAULT_ZOOM_SCALE, Double.class);
399+
if (key != null) {
400+
double value = (double) configurationMap.get(key);
401+
configuration.startZoomScale((float) value);
402+
}
389403
}
390404
}
391405

android/src/main/java/com/pspdfkit/flutter/pspdfkit/PSPDFKitView.kt

+114-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.pspdfkit.flutter.pspdfkit
33
import android.annotation.SuppressLint
44
import android.content.Context
55
import android.content.MutableContextWrapper
6+
import android.graphics.RectF
67
import android.net.Uri
78
import android.util.Log
89
import android.view.View
@@ -12,15 +13,18 @@ import androidx.fragment.app.FragmentContainerView
1213
import androidx.fragment.app.FragmentManager
1314
import androidx.fragment.app.commit
1415
import androidx.fragment.app.commitNow
16+
import com.pspdfkit.annotations.AnnotationType
1517
import com.pspdfkit.document.formatters.DocumentJsonFormatter
1618
import com.pspdfkit.document.processor.PdfProcessor
19+
import com.pspdfkit.document.processor.PdfProcessor.ProcessorProgress
1720
import com.pspdfkit.document.processor.PdfProcessorTask
1821
import com.pspdfkit.flutter.pspdfkit.AnnotationConfigurationAdaptor.Companion.convertAnnotationConfigurations
1922
import com.pspdfkit.flutter.pspdfkit.toolbar.FlutterMenuGroupingRule
2023
import com.pspdfkit.flutter.pspdfkit.toolbar.FlutterViewModeController
2124
import com.pspdfkit.flutter.pspdfkit.util.DocumentJsonDataProvider
2225
import com.pspdfkit.flutter.pspdfkit.util.Preconditions.requireNotNullNotEmpty
23-
import com.pspdfkit.flutter.pspdfkit.util.ProcessorHelper
26+
import com.pspdfkit.flutter.pspdfkit.util.ProcessorHelper.annotationTypeFromString
27+
import com.pspdfkit.flutter.pspdfkit.util.ProcessorHelper.processModeFromString
2428
import com.pspdfkit.flutter.pspdfkit.util.addFileSchemeIfMissing
2529
import com.pspdfkit.flutter.pspdfkit.util.areValidIndexes
2630
import com.pspdfkit.flutter.pspdfkit.util.isImageDocument
@@ -38,13 +42,11 @@ import io.flutter.plugin.common.StandardMessageCodec
3842
import io.flutter.plugin.platform.PlatformView
3943
import io.flutter.plugin.platform.PlatformViewFactory
4044
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
41-
import io.reactivex.rxjava3.disposables.Disposable
4245
import io.reactivex.rxjava3.schedulers.Schedulers
46+
import io.reactivex.rxjava3.subscribers.DisposableSubscriber
4347
import org.json.JSONObject
4448
import java.io.ByteArrayOutputStream
4549
import java.io.File
46-
import java.io.FileOutputStream
47-
4850

4951
internal class PSPDFKitView(
5052
val context: Context,
@@ -67,7 +69,6 @@ internal class PSPDFKitView(
6769
val password = configurationAdapter.password
6870
val pdfConfiguration = configurationAdapter.build()
6971
val toolbarGroupingItems: List<Any>? = configurationMap?.get("toolbarItemGrouping") as List<Any>?
70-
7172
val measurementValueConfigurations =
7273
configurationMap?.get("measurementValueConfigurations") as List<Map<String, Any>>?
7374

@@ -144,7 +145,7 @@ internal class PSPDFKitView(
144145
if (!pdfUiFragment.isAdded) {
145146
return
146147
}
147-
val document = pdfUiFragment.document ?: return
148+
var document = pdfUiFragment.document ?: return
148149

149150
when (call.method) {
150151
"applyInstantJson" -> {
@@ -481,6 +482,113 @@ internal class PSPDFKitView(
481482
result.error("DocumentException", e.message, null)
482483
}
483484
}
485+
"zoomToRect" -> {
486+
try {
487+
val pageIndex:Int = requireNotNull(call.argument("pageIndex"))
488+
val rect: Map<String,Double> = requireNotNull(call.argument("rect"))
489+
var duration:Long = 0
490+
if(call.hasArgument("duration")){
491+
duration = requireNotNull(call.argument("duration"))
492+
}
493+
val x = requireNotNull(rect["left"])
494+
val y = requireNotNull(rect["top"])
495+
val width = requireNotNull(rect["width"])
496+
val height = requireNotNull(rect["height"])
497+
val zooRect = RectF(x.toFloat(),y.toFloat(),(x+width).toFloat(),(y+height).toFloat())
498+
pdfUiFragment.pdfFragment?.zoomTo(zooRect,pageIndex, duration)
499+
result.success(true)
500+
} catch (e: Exception) {
501+
result.error("DocumentException", e.message, null)
502+
}
503+
}
504+
"getVisibleRect" -> {
505+
val pageIndex = requireNotNull(call.argument("pageIndex")) as Int
506+
if (pageIndex < 0 || pageIndex >= document.pageCount) {
507+
result.error("InvalidArgument", "pageIndex is required", null)
508+
} else {
509+
val visiblePdfRect = RectF()
510+
pdfUiFragment.pdfFragment?.getVisiblePdfRect(visiblePdfRect, pageIndex)
511+
result.success(
512+
mapOf(
513+
"left" to visiblePdfRect.left,
514+
"top" to visiblePdfRect.top,
515+
"height" to visiblePdfRect.height(),
516+
"width" to visiblePdfRect.width()
517+
)
518+
)
519+
}
520+
}
521+
"getZoomScale" -> {
522+
val pageIndex = requireNotNull(call.argument("pageIndex")) as Int
523+
if (pageIndex < 0 || pageIndex >= document.pageCount) {
524+
result.error("InvalidArgument", "pageIndex is out of bounds", null)
525+
} else {
526+
val zoomScale = pdfUiFragment.pdfFragment?.getZoomScale(pageIndex)
527+
result.success(zoomScale)
528+
}
529+
}
530+
"processAnnotations" -> {
531+
val outputFilePath:String? = call.argument<String>("destinationPath")
532+
val annotationTypeString:String? = call.argument<String>("type")
533+
val processingModeString:String? = call.argument<String>("processingMode")
534+
535+
// Check if the output path is valid.
536+
if (outputFilePath.isNullOrEmpty()) {
537+
result.error("InvalidArgument", "Output path must be a valid string", null)
538+
return
539+
}
540+
541+
// Check if the annotation type is valid.
542+
if (annotationTypeString.isNullOrEmpty()) {
543+
result.error("InvalidArgument", "Annotation type must be a valid string", null)
544+
return
545+
}
546+
547+
// Check if the processing mode is valid.
548+
if (processingModeString.isNullOrEmpty()) {
549+
result.error("InvalidArgument", "Processing mode must be a valid string", null)
550+
return
551+
}
552+
553+
// Get the annotation type and processing mode.
554+
val annotationType = annotationTypeFromString(
555+
annotationTypeString
556+
)
557+
val processingMode = processModeFromString(processingModeString)
558+
val outputPath = File(outputFilePath)
559+
560+
if (outputPath.parentFile?.exists() == true || outputPath.parentFile?.mkdirs() == true) {
561+
Log.d(LOG_TAG, "Output path is valid: $outputPath")
562+
} else {
563+
result.error("InvalidArgument", "Output path ${outputPath.absolutePath} is invalid", null)
564+
return
565+
}
566+
567+
// Check if we need to process all annotations or only annotations of a specific type.
568+
val task = if (annotationType == AnnotationType.NONE) {
569+
PdfProcessorTask.fromDocument(document).changeAllAnnotations(processingMode)
570+
} else {
571+
PdfProcessorTask.fromDocument(document)
572+
.changeAnnotationsOfType(annotationType, processingMode)
573+
}
574+
575+
PdfProcessor.processDocumentAsync(task, outputPath)
576+
.subscribeOn(Schedulers.io())
577+
.observeOn(AndroidSchedulers.mainThread())
578+
.subscribeWith(object : DisposableSubscriber<ProcessorProgress?>() {
579+
override fun onComplete() {
580+
result.success(true)
581+
}
582+
583+
override fun onNext(t: ProcessorProgress?) {
584+
// No-op
585+
}
586+
587+
override fun onError(t: Throwable) {
588+
result.error("AnnotationException", t.message, null)
589+
}
590+
})
591+
}
484592
else -> result.notImplemented()
485593
}
486594
}
@@ -512,7 +620,6 @@ class PSPDFKitViewFactory(
512620
) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
513621
override fun create(context: Context?, viewId: Int, args: Any?): PlatformView {
514622
val creationParams = args as Map<String?, Any?>?
515-
516623
return PSPDFKitView(
517624
context!!,
518625
viewId,

0 commit comments

Comments
 (0)