Skip to content

Commit

Permalink
Release 3.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PSPDFKit committed May 3, 2024
1 parent dfe418c commit 4d53995
Show file tree
Hide file tree
Showing 33 changed files with 766 additions and 63 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
## Newest Release

### 3.10.0 - 03 May 2024
- 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)
- Updates for PSPDFKit 2024.2.1 for Android.
- Updates for PSPDFKit 13.4.1 for iOS.

## Previous Releases

### 3.9.1 - 12 Apr 2024
- Downgrades to AGP 7.* for backward compatibility (J#HYB-290)
- Allow null value for `Pspdfkit.setLicenseKey` (J#HYB-294)
- Updates for PSPDFKit 2024.2.1 for Android (J#HYB-303)

## Previous Releases

### 3.9.0 - 22 Mar 2024

- Adds annotation toolbar customization for iOS and Android. (J#HYB-209)
Expand Down
5 changes: 5 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.compose.material:material:1.6.5"
implementation "androidx.compose.material:material:1.6.3"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
implementation "androidx.compose.foundation:foundation:1.6.3"
implementation "androidx.compose.ui:ui:1.6.3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,59 @@ package com.pspdfkit.flutter.pspdfkit
import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.pspdfkit.annotations.measurements.MeasurementValueConfiguration
import com.pspdfkit.document.PdfDocument
import com.pspdfkit.flutter.pspdfkit.util.MeasurementHelper
import com.pspdfkit.listeners.SimpleDocumentListener
import com.pspdfkit.ui.PdfFragment
import io.flutter.plugin.common.MethodChannel

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

var pdfFragment: PdfFragment? = null

class FlutterPdfUiFragmentCallbacks(val measurementConfigurations: List<Map<String, Any>>?): FragmentManager.FragmentLifecycleCallbacks() {
final
override fun onFragmentAttached(
fm: FragmentManager,
f: Fragment,
context: Context
) {
if (f.tag?.contains("PSPDFKit.Fragment") == true) {
EventDispatcher.getInstance().notifyPdfFragmentAdded()
val pdfFragment = f as PdfFragment

pdfFragment.addDocumentListener( object : SimpleDocumentListener() {
if (f !is PdfFragment) {
return
}
if (pdfFragment != null) {
return
}
pdfFragment = f as PdfFragment
pdfFragment?.addDocumentListener( object : SimpleDocumentListener() {
override fun onDocumentLoaded(document: PdfDocument) {
if (measurementConfigurations == null) return
measurementConfigurations.forEach {
MeasurementHelper.addMeasurementConfiguration(pdfFragment, it)
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
)
)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.pspdfkit.flutter.pspdfkit

import android.annotation.SuppressLint
import android.content.Context
import android.content.MutableContextWrapper
import android.net.Uri
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
Expand All @@ -11,19 +13,21 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import androidx.fragment.app.commitNow
import com.pspdfkit.document.formatters.DocumentJsonFormatter
import com.pspdfkit.document.processor.PdfProcessor
import com.pspdfkit.document.processor.PdfProcessorTask
import com.pspdfkit.flutter.pspdfkit.AnnotationConfigurationAdaptor.Companion.convertAnnotationConfigurations
import com.pspdfkit.flutter.pspdfkit.toolbar.FlutterMenuGroupingRule
import com.pspdfkit.flutter.pspdfkit.toolbar.FlutterViewModeController
import com.pspdfkit.flutter.pspdfkit.util.DocumentJsonDataProvider
import com.pspdfkit.flutter.pspdfkit.util.Preconditions.requireNotNullNotEmpty
import com.pspdfkit.flutter.pspdfkit.util.ProcessorHelper
import com.pspdfkit.flutter.pspdfkit.util.addFileSchemeIfMissing
import com.pspdfkit.flutter.pspdfkit.util.areValidIndexes
import com.pspdfkit.flutter.pspdfkit.util.isImageDocument
import com.pspdfkit.forms.ChoiceFormElement
import com.pspdfkit.forms.EditableButtonFormElement
import com.pspdfkit.forms.SignatureFormElement
import com.pspdfkit.forms.TextFormElement
import com.pspdfkit.ui.PdfFragment
import com.pspdfkit.ui.PdfUiFragment
import com.pspdfkit.ui.PdfUiFragmentBuilder
import io.flutter.plugin.common.BinaryMessenger
Expand All @@ -34,17 +38,20 @@ import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import org.json.JSONObject
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream


internal class PSPDFKitView(
val context: Context,
id: Int,
messenger: BinaryMessenger,
documentPath: String? = null,
configurationMap: HashMap<String, Any>? = null,

) : PlatformView, MethodCallHandler {

private var fragmentContainerView: FragmentContainerView? = FragmentContainerView(context)
Expand Down Expand Up @@ -84,9 +91,7 @@ internal class PSPDFKitView(
.build()
}
}

getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks(FlutterPdfUiFragmentCallbacks(measurementValueConfigurations), true)

getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks(FlutterPdfUiFragmentCallbacks(methodChannel,measurementValueConfigurations), true)
getFragmentActivity(context).supportFragmentManager.registerFragmentLifecycleCallbacks( object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentAttached(
fm: FragmentManager,
Expand Down Expand Up @@ -131,6 +136,7 @@ internal class PSPDFKitView(
fragmentContainerView = null
}

@SuppressLint("CheckResult")
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
// Return if the fragment or the document
// are not ready.
Expand Down Expand Up @@ -445,6 +451,35 @@ internal class PSPDFKitView(
result.error("AnnotationException", e.message, null)
}
}
"getPageInfo" -> {
try {
val pageIndex:Int = requireNotNull(call.argument("pageIndex"))
val pageInfo = mapOf(
"width" to document.getPageSize(pageIndex).width,
"height" to document.getPageSize(pageIndex).height,
"label" to document.getPageLabel(pageIndex,false),
"index" to pageIndex,
"rotation" to document.getPageRotation(pageIndex)
)
result.success(pageInfo)
}catch (e:Exception){
result.error("DocumentException",e.message,null)
}
}
"exportPdf" -> {
try {
val fileUrl = document.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()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.pspdfkit.flutter.pspdfkit.util

import com.pspdfkit.document.DocumentPermissions
import com.pspdfkit.document.DocumentSaveOptions
import com.pspdfkit.document.PdfVersion
import java.util.EnumSet

object ProcessorHelper {
fun extractSaveOptions( options: Map<String, Any>): DocumentSaveOptions {
val password: String? = options["password"] as String?
val permissionsList = options["permissions"]as List<String>??: emptyList()
val incremental = options["incremental"] as Boolean? ?: false
val pdfVersion = options["pdfVersion"] as String?
val saveOptions = DocumentSaveOptions(
password,
extractPermissions(permissionsList ),
incremental,
extractPdfVersion(pdfVersion)
)
return saveOptions
}

private fun extractPermissions(permissions: List<String>): EnumSet<DocumentPermissions> {
val documentPermissions = EnumSet.noneOf(DocumentPermissions::class.java)
for (permission in permissions) {
when (permission) {
"printing" -> documentPermissions.add(DocumentPermissions.PRINTING)
"annotationsAndForms" -> documentPermissions.add(DocumentPermissions.ANNOTATIONS_AND_FORMS)
"extractAccessibility" -> documentPermissions.add(DocumentPermissions.EXTRACT_ACCESSIBILITY)
"fillForms" -> documentPermissions.add(DocumentPermissions.FILL_FORMS)
"extract" -> documentPermissions.add(DocumentPermissions.EXTRACT)
"assemble" -> documentPermissions.add(DocumentPermissions.ASSEMBLE)
"printHighQuality" -> documentPermissions.add(DocumentPermissions.PRINT_HIGH_QUALITY)
"modification" -> documentPermissions.add(DocumentPermissions.MODIFICATION)
}
}
return documentPermissions
}

private fun extractPdfVersion(pdfVersion: String?): PdfVersion? {
return when (pdfVersion) {
"pdf_1_0" -> PdfVersion.PDF_1_0
"pdf_1_1" -> PdfVersion.PDF_1_1
"pdf_1_2" -> PdfVersion.PDF_1_2
"pdf_1_3" -> PdfVersion.PDF_1_3
"pdf_1_4" -> PdfVersion.PDF_1_4
"pdf_1_5" -> PdfVersion.PDF_1_5
"pdf_1_6" -> PdfVersion.PDF_1_6
"pdf_1_7" -> PdfVersion.PDF_1_7
else -> null
}
}

fun reversePdfVersion(pdfVersion: PdfVersion): String? {
return when (pdfVersion) {
PdfVersion.PDF_1_0 -> "pdf_1_0"
PdfVersion.PDF_1_1 -> "pdf_1_1"
PdfVersion.PDF_1_2 -> "pdf_1_2"
PdfVersion.PDF_1_3 -> "pdf_1_3"
PdfVersion.PDF_1_4 -> "pdf_1_4"
PdfVersion.PDF_1_5 -> "pdf_1_5"
PdfVersion.PDF_1_6 -> "pdf_1_6"
PdfVersion.PDF_1_7 -> "pdf_1_7"
}
}

fun reversePermissions(permissions: EnumSet<DocumentPermissions>): List<String> {
val permissionsList = mutableListOf<String>()
for (permission in permissions) {
when (permission) {
DocumentPermissions.PRINTING -> permissionsList.add("printing")
DocumentPermissions.ANNOTATIONS_AND_FORMS -> permissionsList.add("annotationsAndForms")
DocumentPermissions.EXTRACT_ACCESSIBILITY -> permissionsList.add("extractAccessibility")
DocumentPermissions.FILL_FORMS -> permissionsList.add("fillForms")
DocumentPermissions.EXTRACT -> permissionsList.add("extract")
DocumentPermissions.ASSEMBLE -> permissionsList.add("assemble")
DocumentPermissions.PRINT_HIGH_QUALITY -> permissionsList.add("printHighQuality")
DocumentPermissions.MODIFICATION -> permissionsList.add("modification")
else -> permissionsList.add("printing")
}
}
return permissionsList
}

}
4 changes: 2 additions & 2 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ host_cpu = RbConfig::CONFIG["host_cpu"]

target "Runner" do
flutter_install_all_ios_pods __dir__
# # PSPDFKit iOS SDK version specified by PSPDFKit Flutter Plugin. Do not remove this line.
# # Instant iOS SDK version specified by PSPDFKit Flutter Plugin. Do not remove this line.
# PSPDFKit iOS SDK version specified by PSPDFKit Flutter Plugin. Do not remove this line.
# Instant iOS SDK version specified by PSPDFKit Flutter Plugin. Do not remove this line.
use_modular_headers!
end

Expand Down
8 changes: 8 additions & 0 deletions example/lib/examples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:pspdfkit_example/models/papsdkit_example_item.dart';
import 'package:pspdfkit_example/pspdfkit_toolbar_customization.dart';

import 'pspdfkit_annotation_preset_customisation.dart';
import 'pspdfkit_document_example.dart';
import 'pspdfkit_event_listeners_example.dart';
import 'utils/file_utils.dart';
import 'utils/platform_utils.dart';
Expand Down Expand Up @@ -67,6 +68,13 @@ List<PspdfkitExampleItem> examples(BuildContext context) => [
description: 'Opens an image document.',
onTap: () => showImage(context),
),
PspdfkitExampleItem(
title: 'Document Example',
description: 'Shows how to get document properties after loading.',
onTap: () async {
await extractAsset(context, _documentPath).then((value) => goTo(
PspdfkitDocumentExample(documentPath: value.path), context));
}),
PspdfkitExampleItem(
title: 'Dark Theme',
description: 'Opens a document in night mode with a custom dark theme.',
Expand Down
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void main() {
//
// To set the license key for the currently running platform, use:
// Pspdfkit.setLicenseKey(null);

Pspdfkit.setLicenseKey(null);
runApp(const MyApp());
}
Expand Down
4 changes: 3 additions & 1 deletion example/lib/pspdfkit_basic_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class PspdfkitBasicExample extends StatelessWidget {
padding: PlatformUtils.isAndroid()
? const EdgeInsets.only(top: kToolbarHeight)
: null,
child: PspdfkitWidget(documentPath: documentPath))));
child: PspdfkitWidget(
documentPath: documentPath,
))));
}
}
Loading

0 comments on commit 4d53995

Please sign in to comment.