Skip to content

Commit

Permalink
Release 3.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PSPDFKit committed Jun 22, 2024
1 parent 4362faf commit a7cc9f5
Show file tree
Hide file tree
Showing 42 changed files with 1,156 additions and 107 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
## Newest Release

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

## Previous Releases

### 3.10.1 - 28 May 2024
- Fixes issue where ViewUtils.generateViewId() cannot be resolved. (J#HYB-379)

### 3.10.0 - 03 May 2024
- Adds APIs to get page information such as size, rotation and label. (J#HYB-195)
- Adds APIs to get page information such as size, rotation, and label. (J#HYB-195)
- Adds document load callbacks to `PspdfkitWidget`. (J#HYB-195)
- Adds page change callback to `PspdfkitWidget`. (J#HYB-195)
- Adds support for exporting document as binary data. (J#HYB-337)
Expand Down Expand Up @@ -116,7 +120,7 @@

### 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.
- 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.
- 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)
Expand Down
Binary file modified License-Evaluation.pdf
Binary file not shown.
58 changes: 49 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,41 @@ Platform specific README exists for [Android](android/) and [iOS](ios/).
cd pspdfkit_demo
```

3. Open the app’s Gradle build file, `android/app/build.gradle`:
3. Update the `pluginManagement` block in the `android/settings.gradle` file as follows:

```diff
pluginManagement {
...
+ buildscript {
+ repositories {
+ mavenCentral()
+ maven {
+ url = uri("https://storage.googleapis.com/r8-releases/raw")
+ }
+ }
+ dependencies {
+ classpath("com.android.tools:r8:8.3.37")
+ }
+ }
}
// Upgrade Kotlin version.
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
- id "org.jetbrains.kotlin.android" version "1.7.10" apply false
+ id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}
```
This step involves enabling R8 for code shrinking (not required for AGP 8.* and above) and upgrading the Kotlin version.
4. Open the app’s Gradle build file, `android/app/build.gradle`:
```bash
open android/app/build.gradle
```
4. Modify the compile SDK version and the minimum SDK version:
5. Modify the compile SDK version and the minimum SDK version:
```diff
android {
Expand All @@ -113,24 +141,36 @@ Platform specific README exists for [Android](android/) and [iOS](ios/).
+ minSdkVersion 21
...
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
}
// If you have this block, update the `jvmTarget` to 17.
kotlinOptions {
- jvmTarget = '1.8'
+ jvmTarget = '17'
}
...
}
```

5. Add the AppCompat AndroidX library to your `android/app/build.gradle` file:
6. Add the AppCompat AndroidX library to your `android/app/build.gradle` file:
```diff
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation 'androidx.appcompat:appcompat:1.4.0'
}
```
6. Open the project’s main activity class, `android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt`:
7. Open the project’s main activity class, `android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt`:
```bash
open android/app/src/main/kotlin/com/example/pspdfkit_demo/pspdfkit_demo/MainActivity.kt
```
7. Change the base `Activity` to extend `FlutterAppCompatActivity`:
8. Change the base `Activity` to extend `FlutterAppCompatActivity`:
```diff
- import io.flutter.embedding.android.FlutterActivity;
Expand All @@ -156,17 +196,17 @@ Platform specific README exists for [Android](android/) and [iOS](ios/).
```
**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.
8. Update the theme in `android/app/src/main/res/values/styles.xml` to use `PSPDFKit.Theme.default` as the parent:
9. Update the theme in `android/app/src/main/res/values/styles.xml` to use `PSPDFKit.Theme.default` as the parent:
```diff
- <style name="NormalTheme" parent="Theme.AppCompat.Light.NoActionBar">
+ <style name="NormalTheme" parent="PSPDFKit.Theme.Default">
```
This is to customize the theme of the PSPDFKit UI. You can read more about this in the [appearance styling][] guide.
9. [Start your Android emulator][start-the-emulator], or connect a device.
10. [Start your Android emulator][start-the-emulator], or connect a device.
10. Run the app with:
11. Run the app with:
```bash
flutter run
Expand Down
2 changes: 1 addition & 1 deletion 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 = '2024.2.1'
ext.pspdfkitVersion = '2024.3.0'
}

ext.pspdfkitMavenModuleName = 'pspdfkit'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ConfigurationAdapter {
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.pspdfkit.document.PdfDocument
import com.pspdfkit.flutter.pspdfkit.document.FlutterPdfDocument
import com.pspdfkit.flutter.pspdfkit.util.MeasurementHelper
import com.pspdfkit.listeners.SimpleDocumentListener
import com.pspdfkit.listeners.DocumentListener
import com.pspdfkit.ui.PdfFragment
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel

class FlutterPdfUiFragmentCallbacks(val methodChannel: MethodChannel,val measurementConfigurations: List<Map<String, Any>>?): FragmentManager.FragmentLifecycleCallbacks() {
class FlutterPdfUiFragmentCallbacks(
private val methodChannel: MethodChannel, private val measurementConfigurations:
List<Map<String, Any>>?,
private val binaryMessenger: BinaryMessenger
) : FragmentManager.FragmentLifecycleCallbacks(), DocumentListener {

var pdfFragment: PdfFragment? = null
private var pdfFragment: PdfFragment? = null
private var flutterPdfDocument: FlutterPdfDocument? = null

override fun onFragmentAttached(
fm: FragmentManager,
f: Fragment,
context: Context
fm: FragmentManager,
f: Fragment,
context: Context
) {
if (f.tag?.contains("PSPDFKit.Fragment") == true) {
EventDispatcher.getInstance().notifyPdfFragmentAdded()
Expand All @@ -27,37 +34,55 @@ class FlutterPdfUiFragmentCallbacks(val methodChannel: MethodChannel,val measur
return
}
pdfFragment = f as PdfFragment
pdfFragment?.addDocumentListener( object : SimpleDocumentListener() {
override fun onDocumentLoaded(document: PdfDocument) {
measurementConfigurations?.forEach {
MeasurementHelper.addMeasurementConfiguration(pdfFragment!!, it)
}
methodChannel.invokeMethod("onDocumentLoaded", mapOf(
"documentId" to document.uid
))
}

override fun onPageChanged(document: PdfDocument, pageIndex: Int) {
super.onPageChanged(document, pageIndex)
methodChannel.invokeMethod(
"onPageChanged",
mapOf(
"documentId" to document.uid,
"pageIndex" to pageIndex
)
)
}

override fun onDocumentLoadFailed(exception: Throwable) {
super.onDocumentLoadFailed(exception)
methodChannel.invokeMethod(
"onDocumentLoadFailed",
mapOf(
"error" to exception.message
)
)
}
})
pdfFragment?.addDocumentListener(this)
}
}

override fun onDocumentLoaded(document: PdfDocument) {
measurementConfigurations?.forEach {
MeasurementHelper.addMeasurementConfiguration(pdfFragment!!, it)
}
methodChannel.invokeMethod(
"onDocumentLoaded", mapOf(
"documentId" to document.uid
)
)

flutterPdfDocument =
FlutterPdfDocument(document, binaryMessenger);
}

override fun onPageChanged(document: PdfDocument, pageIndex: Int) {
super.onPageChanged(document, pageIndex)
methodChannel.invokeMethod(
"onPageChanged",
mapOf(
"documentId" to document.uid,
"pageIndex" to pageIndex
)
)
}

override fun onDocumentLoadFailed(exception: Throwable) {
super.onDocumentLoadFailed(exception)
methodChannel.invokeMethod(
"onDocumentLoadFailed",
mapOf(
"error" to exception.message
)
)
}

override fun onFragmentDetached(fm: FragmentManager, f: Fragment) {
if (f.tag?.contains("PSPDFKit.Fragment") == true) {
if (f !is PdfFragment) {
return
}
if (pdfFragment == f) {
pdfFragment?.removeDocumentListener(this)
pdfFragment = null
flutterPdfDocument = null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ internal class PSPDFKitView(
.build()
}
}
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks(FlutterPdfUiFragmentCallbacks(methodChannel,measurementValueConfigurations), true)
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks(FlutterPdfUiFragmentCallbacks(methodChannel,
measurementValueConfigurations, messenger), true)
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks( object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentAttached(
fm: FragmentManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.pspdfkit.flutter.pspdfkit.document

import android.util.Log
import com.pspdfkit.document.PdfDocument
import com.pspdfkit.flutter.pspdfkit.PSPDFKitView
import com.pspdfkit.flutter.pspdfkit.forms.FormHelper
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import java.io.File

class FlutterPdfDocument(
private val pdfDocument: PdfDocument, messenger: BinaryMessenger,
) : MethodCallHandler {
init {
val channel = MethodChannel(messenger, "com.pspdfkit.document.${pdfDocument.uid}")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
"getPageInfo" -> {
val pageIndex = call.argument<Int>("pageIndex") ?: -1
if (pageIndex < 0 || pageIndex >= pdfDocument.pageCount) {
result.error("InvalidArgument", "pageIndex is required", null)
} else {
try {
val pageInfo = getPageInfo(pageIndex)
result.success(pageInfo)
} catch (e: Exception) {
result.error("Error", e.message, null)
}
}
}
"getFormFields" -> {
try {
val formFields = pdfDocument.formProvider.formFields
val formFieldsMap = FormHelper.formFieldPropertiesToMap(formFields)
result.success(formFieldsMap)
} catch (e: Exception) {
result.error("Error", e.message, null)
}
}
"exportPdf" -> {
try {
val fileUrl = pdfDocument.documentSource.fileUri?.path
if (fileUrl == null) {
result.error("DocumentException", "Document source is not a file", null)
return
}
val data:ByteArray = fileUrl.let { File(it).readBytes() }
result.success(data)
} catch (e: Exception) {
Log.e(LOG_TAG, "Error while exporting PDF", e)
result.error("DocumentException", e.message, null)
}
}

else -> {
result.notImplemented()
}
}
}

private fun getPageInfo(pageIndex: Int): Map<String, Any?> {
val pageInfo = mapOf(
"width" to pdfDocument.getPageSize(pageIndex).width,
"height" to pdfDocument.getPageSize(pageIndex).height,
"label" to pdfDocument.getPageLabel(pageIndex, false),
"index" to pageIndex,
"rotation" to pdfDocument.getPageRotation(pageIndex)
)
return pageInfo
}

companion object {
const val LOG_TAG = "FlutterPdfDocument"
}
}
Loading

0 comments on commit a7cc9f5

Please sign in to comment.