Skip to content

Commit a7cc9f5

Browse files
author
PSPDFKit
committed
Release 3.11.0
1 parent 4362faf commit a7cc9f5

Some content is hidden

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

42 files changed

+1156
-107
lines changed

CHANGELOG.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
## Newest Release
22

3-
### 3.10.1 - 28 May 2024
4-
- Fixes issue where ViewUtils.generateViewId() cannot be resolved. (J#HYB-379)
3+
### 3.11.0 - 21 Jun 2024
4+
- Adds API to get form filed properties to PdfDocument. (J#HYB-169)
5+
- Adds instant synchronization support on Web. (J#HYB-377)
56

67
## Previous Releases
78

9+
### 3.10.1 - 28 May 2024
10+
- Fixes issue where ViewUtils.generateViewId() cannot be resolved. (J#HYB-379)
11+
812
### 3.10.0 - 03 May 2024
9-
- Adds APIs to get page information such as size, rotation and label. (J#HYB-195)
13+
- Adds APIs to get page information such as size, rotation, and label. (J#HYB-195)
1014
- Adds document load callbacks to `PspdfkitWidget`. (J#HYB-195)
1115
- Adds page change callback to `PspdfkitWidget`. (J#HYB-195)
1216
- Adds support for exporting document as binary data. (J#HYB-337)
@@ -116,7 +120,7 @@
116120

117121
### 3.2.0 - 14 Feb 2022
118122

119-
- 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.
123+
- 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-migration-guide/) for this release.
120124
- PSPDFKit now requires Flutter 2.10.1 or later. (#33016)
121125
- Adds a new configuration option to disable autosave. (#32857)
122126
- Adds a new example illustrating manual saving of documents with autosave disabled. (#32857)

License-Evaluation.pdf

-33.6 KB
Binary file not shown.

README.md

+49-9
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,41 @@ Platform specific README exists for [Android](android/) and [iOS](ios/).
9595
cd pspdfkit_demo
9696
```
9797

98-
3. Open the app’s Gradle build file, `android/app/build.gradle`:
98+
3. Update the `pluginManagement` block in the `android/settings.gradle` file as follows:
99+
100+
```diff
101+
pluginManagement {
102+
...
103+
+ buildscript {
104+
+ repositories {
105+
+ mavenCentral()
106+
+ maven {
107+
+ url = uri("https://storage.googleapis.com/r8-releases/raw")
108+
+ }
109+
+ }
110+
+ dependencies {
111+
+ classpath("com.android.tools:r8:8.3.37")
112+
+ }
113+
+ }
114+
}
115+
116+
// Upgrade Kotlin version.
117+
plugins {
118+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
119+
id "com.android.application" version "7.3.0" apply false
120+
- id "org.jetbrains.kotlin.android" version "1.7.10" apply false
121+
+ id "org.jetbrains.kotlin.android" version "1.8.22" apply false
122+
}
123+
```
124+
This step involves enabling R8 for code shrinking (not required for AGP 8.* and above) and upgrading the Kotlin version.
125+
126+
4. Open the app’s Gradle build file, `android/app/build.gradle`:
99127
100128
```bash
101129
open android/app/build.gradle
102130
```
103131
104-
4. Modify the compile SDK version and the minimum SDK version:
132+
5. Modify the compile SDK version and the minimum SDK version:
105133
106134
```diff
107135
android {
@@ -113,24 +141,36 @@ Platform specific README exists for [Android](android/) and [iOS](ios/).
113141
+ minSdkVersion 21
114142
...
115143
}
144+
compileOptions {
145+
- sourceCompatibility JavaVersion.VERSION_1_8
146+
- targetCompatibility JavaVersion.VERSION_1_8
147+
+ sourceCompatibility JavaVersion.VERSION_17
148+
+ targetCompatibility JavaVersion.VERSION_17
149+
}
150+
151+
// If you have this block, update the `jvmTarget` to 17.
152+
kotlinOptions {
153+
- jvmTarget = '1.8'
154+
+ jvmTarget = '17'
155+
}
156+
...
116157
}
117158
```
118-
119-
5. Add the AppCompat AndroidX library to your `android/app/build.gradle` file:
159+
6. Add the AppCompat AndroidX library to your `android/app/build.gradle` file:
120160
121161
```diff
122162
dependencies {
123163
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
124164
+ implementation 'androidx.appcompat:appcompat:1.4.0'
125165
}
126166
```
127-
6. Open the project’s main activity class, `android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt`:
167+
7. Open the project’s main activity class, `android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt`:
128168
129169
```bash
130170
open android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt
131171
```
132172
133-
7. Change the base `Activity` to extend `FlutterAppCompatActivity`:
173+
8. Change the base `Activity` to extend `FlutterAppCompatActivity`:
134174
135175
```diff
136176
- import io.flutter.embedding.android.FlutterActivity;
@@ -156,17 +196,17 @@ Platform specific README exists for [Android](android/) and [iOS](ios/).
156196
```
157197
**NOTE:** <code>FlutterAppCompatActivity</code> isn’t an official part of the Flutter SDK. It’s a custom <code>Activity</code> that extends <code>AppCompatActivity</code> from the AndroidX AppCompat library, and it’s necessary to use PSPDFKit for Android with Flutter. You can read more about this in the [AppCompatActivity Migration][] guide.
158198
159-
8. Update the theme in `android/app/src/main/res/values/styles.xml` to use `PSPDFKit.Theme.default` as the parent:
199+
9. Update the theme in `android/app/src/main/res/values/styles.xml` to use `PSPDFKit.Theme.default` as the parent:
160200
161201
```diff
162202
- <style name="NormalTheme" parent="Theme.AppCompat.Light.NoActionBar">
163203
+ <style name="NormalTheme" parent="PSPDFKit.Theme.Default">
164204
```
165205
This is to customize the theme of the PSPDFKit UI. You can read more about this in the [appearance styling][] guide.
166206
167-
9. [Start your Android emulator][start-the-emulator], or connect a device.
207+
10. [Start your Android emulator][start-the-emulator], or connect a device.
168208
169-
10. Run the app with:
209+
11. Run the app with:
170210
171211
```bash
172212
flutter run

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

4444
ext.pspdfkitMavenModuleName = 'pspdfkit'

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

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class ConfigurationAdapter {
4949
private static final String ENABLE_TEXT_SELECTION = "enableTextSelection";
5050
private static final String DISABLE_AUTOSAVE = "disableAutosave";
5151

52-
5352
// Document Presentation Options
5453
private static final String PAGE_MODE = "pageMode";
5554
private static final String SPREAD_FITTING = "spreadFitting";

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

+62-37
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ import android.content.Context
44
import androidx.fragment.app.Fragment
55
import androidx.fragment.app.FragmentManager
66
import com.pspdfkit.document.PdfDocument
7+
import com.pspdfkit.flutter.pspdfkit.document.FlutterPdfDocument
78
import com.pspdfkit.flutter.pspdfkit.util.MeasurementHelper
8-
import com.pspdfkit.listeners.SimpleDocumentListener
9+
import com.pspdfkit.listeners.DocumentListener
910
import com.pspdfkit.ui.PdfFragment
11+
import io.flutter.plugin.common.BinaryMessenger
1012
import io.flutter.plugin.common.MethodChannel
1113

12-
class FlutterPdfUiFragmentCallbacks(val methodChannel: MethodChannel,val measurementConfigurations: List<Map<String, Any>>?): FragmentManager.FragmentLifecycleCallbacks() {
14+
class FlutterPdfUiFragmentCallbacks(
15+
private val methodChannel: MethodChannel, private val measurementConfigurations:
16+
List<Map<String, Any>>?,
17+
private val binaryMessenger: BinaryMessenger
18+
) : FragmentManager.FragmentLifecycleCallbacks(), DocumentListener {
1319

14-
var pdfFragment: PdfFragment? = null
20+
private var pdfFragment: PdfFragment? = null
21+
private var flutterPdfDocument: FlutterPdfDocument? = null
1522

1623
override fun onFragmentAttached(
17-
fm: FragmentManager,
18-
f: Fragment,
19-
context: Context
24+
fm: FragmentManager,
25+
f: Fragment,
26+
context: Context
2027
) {
2128
if (f.tag?.contains("PSPDFKit.Fragment") == true) {
2229
EventDispatcher.getInstance().notifyPdfFragmentAdded()
@@ -27,37 +34,55 @@ class FlutterPdfUiFragmentCallbacks(val methodChannel: MethodChannel,val measur
2734
return
2835
}
2936
pdfFragment = f as PdfFragment
30-
pdfFragment?.addDocumentListener( object : SimpleDocumentListener() {
31-
override fun onDocumentLoaded(document: PdfDocument) {
32-
measurementConfigurations?.forEach {
33-
MeasurementHelper.addMeasurementConfiguration(pdfFragment!!, it)
34-
}
35-
methodChannel.invokeMethod("onDocumentLoaded", mapOf(
36-
"documentId" to document.uid
37-
))
38-
}
39-
40-
override fun onPageChanged(document: PdfDocument, pageIndex: Int) {
41-
super.onPageChanged(document, pageIndex)
42-
methodChannel.invokeMethod(
43-
"onPageChanged",
44-
mapOf(
45-
"documentId" to document.uid,
46-
"pageIndex" to pageIndex
47-
)
48-
)
49-
}
50-
51-
override fun onDocumentLoadFailed(exception: Throwable) {
52-
super.onDocumentLoadFailed(exception)
53-
methodChannel.invokeMethod(
54-
"onDocumentLoadFailed",
55-
mapOf(
56-
"error" to exception.message
57-
)
58-
)
59-
}
60-
})
37+
pdfFragment?.addDocumentListener(this)
38+
}
39+
}
40+
41+
override fun onDocumentLoaded(document: PdfDocument) {
42+
measurementConfigurations?.forEach {
43+
MeasurementHelper.addMeasurementConfiguration(pdfFragment!!, it)
44+
}
45+
methodChannel.invokeMethod(
46+
"onDocumentLoaded", mapOf(
47+
"documentId" to document.uid
48+
)
49+
)
50+
51+
flutterPdfDocument =
52+
FlutterPdfDocument(document, binaryMessenger);
53+
}
54+
55+
override fun onPageChanged(document: PdfDocument, pageIndex: Int) {
56+
super.onPageChanged(document, pageIndex)
57+
methodChannel.invokeMethod(
58+
"onPageChanged",
59+
mapOf(
60+
"documentId" to document.uid,
61+
"pageIndex" to pageIndex
62+
)
63+
)
64+
}
65+
66+
override fun onDocumentLoadFailed(exception: Throwable) {
67+
super.onDocumentLoadFailed(exception)
68+
methodChannel.invokeMethod(
69+
"onDocumentLoadFailed",
70+
mapOf(
71+
"error" to exception.message
72+
)
73+
)
74+
}
75+
76+
override fun onFragmentDetached(fm: FragmentManager, f: Fragment) {
77+
if (f.tag?.contains("PSPDFKit.Fragment") == true) {
78+
if (f !is PdfFragment) {
79+
return
80+
}
81+
if (pdfFragment == f) {
82+
pdfFragment?.removeDocumentListener(this)
83+
pdfFragment = null
84+
flutterPdfDocument = null
85+
}
6186
}
6287
}
6388
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ internal class PSPDFKitView(
9191
.build()
9292
}
9393
}
94-
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks(FlutterPdfUiFragmentCallbacks(methodChannel,measurementValueConfigurations), true)
94+
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks(FlutterPdfUiFragmentCallbacks(methodChannel,
95+
measurementValueConfigurations, messenger), true)
9596
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks( object : FragmentManager.FragmentLifecycleCallbacks() {
9697
override fun onFragmentAttached(
9798
fm: FragmentManager,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.pspdfkit.flutter.pspdfkit.document
2+
3+
import android.util.Log
4+
import com.pspdfkit.document.PdfDocument
5+
import com.pspdfkit.flutter.pspdfkit.PSPDFKitView
6+
import com.pspdfkit.flutter.pspdfkit.forms.FormHelper
7+
import io.flutter.plugin.common.BinaryMessenger
8+
import io.flutter.plugin.common.MethodCall
9+
import io.flutter.plugin.common.MethodChannel
10+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
11+
import java.io.File
12+
13+
class FlutterPdfDocument(
14+
private val pdfDocument: PdfDocument, messenger: BinaryMessenger,
15+
) : MethodCallHandler {
16+
init {
17+
val channel = MethodChannel(messenger, "com.pspdfkit.document.${pdfDocument.uid}")
18+
channel.setMethodCallHandler(this)
19+
}
20+
21+
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
22+
when (call.method) {
23+
"getPageInfo" -> {
24+
val pageIndex = call.argument<Int>("pageIndex") ?: -1
25+
if (pageIndex < 0 || pageIndex >= pdfDocument.pageCount) {
26+
result.error("InvalidArgument", "pageIndex is required", null)
27+
} else {
28+
try {
29+
val pageInfo = getPageInfo(pageIndex)
30+
result.success(pageInfo)
31+
} catch (e: Exception) {
32+
result.error("Error", e.message, null)
33+
}
34+
}
35+
}
36+
"getFormFields" -> {
37+
try {
38+
val formFields = pdfDocument.formProvider.formFields
39+
val formFieldsMap = FormHelper.formFieldPropertiesToMap(formFields)
40+
result.success(formFieldsMap)
41+
} catch (e: Exception) {
42+
result.error("Error", e.message, null)
43+
}
44+
}
45+
"exportPdf" -> {
46+
try {
47+
val fileUrl = pdfDocument.documentSource.fileUri?.path
48+
if (fileUrl == null) {
49+
result.error("DocumentException", "Document source is not a file", null)
50+
return
51+
}
52+
val data:ByteArray = fileUrl.let { File(it).readBytes() }
53+
result.success(data)
54+
} catch (e: Exception) {
55+
Log.e(LOG_TAG, "Error while exporting PDF", e)
56+
result.error("DocumentException", e.message, null)
57+
}
58+
}
59+
60+
else -> {
61+
result.notImplemented()
62+
}
63+
}
64+
}
65+
66+
private fun getPageInfo(pageIndex: Int): Map<String, Any?> {
67+
val pageInfo = mapOf(
68+
"width" to pdfDocument.getPageSize(pageIndex).width,
69+
"height" to pdfDocument.getPageSize(pageIndex).height,
70+
"label" to pdfDocument.getPageLabel(pageIndex, false),
71+
"index" to pageIndex,
72+
"rotation" to pdfDocument.getPageRotation(pageIndex)
73+
)
74+
return pageInfo
75+
}
76+
77+
companion object {
78+
const val LOG_TAG = "FlutterPdfDocument"
79+
}
80+
}

0 commit comments

Comments
 (0)