Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {

dependencies {
classpath "com.android.tools.build:gradle:$androidGradlePluginVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
}
}

Expand Down
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Sat Oct 12 10:55:54 PKT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.pspdfkit.annotations.AnnotationType;
import com.pspdfkit.annotations.configuration.AnnotationConfiguration;
import java.util.EnumSet;
import android.content.Context;
import androidx.annotation.NonNull;


class ConfigurationAdapter {
private static final String LOG_TAG = "ConfigurationAdapter";
Expand Down Expand Up @@ -127,11 +133,13 @@ class ConfigurationAdapter {
* @deprecated This key word was deprecated with PSPDFKit for Fluttter 3.1.
* Use {@code FIRST_PAGE_ALWAYS_SINGLE} instead, which replaces it.
*/
@Deprecated
private static final String IS_FIRST_PAGE_ALWAYS_SINGLE = "isFirstPageAlwaysSingle";
/**
* @deprecated This key word was deprecated with PSPDFKit for Fluttter 3.1.
* Use {@code SHOW_BOOKMARKS_ACTION} instead, which replaces it.
*/
@Deprecated
private static final String ENABLE_BOOKMARK_LIST = "enableBookmarkList";

// Document Interaction Values
Expand Down Expand Up @@ -204,6 +212,14 @@ class ConfigurationAdapter {
if (configurationMap != null && !configurationMap.isEmpty()) {
String key = null;

key = getKeyOfType(configurationMap, "defaultAuthorName", String.class);
if (key != null) {
configureDefaultAuthorName((String) configurationMap.get(key), context);
}
key = getKeyOfType(configurationMap, "askForAnnotationUsername", Boolean.class);
if (key != null) {
configureAskForAnnotationUsername((Boolean) configurationMap.get(key), context);
}
key = getKeyOfType(configurationMap, PAGE_MODE, String.class);
if (key != null) {
configurePageMode((String) configurationMap.get(key));
Expand Down Expand Up @@ -403,6 +419,24 @@ class ConfigurationAdapter {
}
}

private void configureDefaultAuthorName(@NonNull String defaultAuthorName, @NonNull Context context) {
PSPDFKitPreferences.get(context).setAnnotationCreator(defaultAuthorName);
Log.d(LOG_TAG, "defaultAuthorName set to: " + defaultAuthorName);
}

private void configureAskForAnnotationUsername(boolean askForAnnotationUsername, @NonNull Context context) {
if (askForAnnotationUsername) {
// Reset the annotation creator to prompt the user
PSPDFKitPreferences.get(context).resetAnnotationCreator();
Log.d(LOG_TAG, "Annotation creator reset to prompt user.");
} else {
// Ensure annotation creator is set to prevent the dialog
if (!PSPDFKitPreferences.get(context).isAnnotationCreatorSet()) {
PSPDFKitPreferences.get(context).setAnnotationCreator("");
Log.d(LOG_TAG, "Annotation creator set to empty string to prevent dialog.");
}
}
}

private void configurePageTransition(@NonNull final String transition) {
switch (transition) {
Expand Down Expand Up @@ -596,8 +630,10 @@ private void configureInvertColors(boolean invertColors) {
private void configureEnableAnnotationEditing(boolean enableAnnotationEditing) {
if (enableAnnotationEditing) {
configuration.enableAnnotationEditing();
configuration.enableAnnotationList(); // Enable annotation list when editing is enabled
} else {
configuration.disableAnnotationEditing();
configuration.disableAnnotationList(); // Disable annotation list when editing is disabled
}
}

Expand Down Expand Up @@ -848,8 +884,9 @@ String getPassword() {
}

PdfActivityConfiguration build() {
// Turn on Instant comments;
// Turn on Instant comments;
if (enableInstantComments) {

PdfConfiguration pdfConfiguration = this.configuration.build().getConfiguration();

final List<AnnotationTool> annotationTools = pdfConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ package com.pspdfkit.flutter.pspdfkit
import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.pspdfkit.annotations.AnnotationProvider.OnAnnotationUpdatedListener
import com.pspdfkit.document.PdfDocument
import com.pspdfkit.flutter.pspdfkit.document.FlutterPdfDocument
import com.pspdfkit.flutter.pspdfkit.util.MeasurementHelper
import com.pspdfkit.listeners.DocumentListener
import com.pspdfkit.ui.PdfFragment
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel
import com.pspdfkit.annotations.Annotation

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

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

override fun onFragmentAttached(
fm: FragmentManager,
Expand Down Expand Up @@ -48,8 +51,31 @@ class FlutterPdfUiFragmentCallbacks(
)
)

flutterPdfDocument =
FlutterPdfDocument(document, binaryMessenger);
flutterPdfDocument = FlutterPdfDocument(document, binaryMessenger)

annotationUpdatedListener = object : OnAnnotationUpdatedListener {
override fun onAnnotationCreated(annotation: Annotation) {
methodChannel.invokeMethod("onAnnotationsChanged", null)
}

override fun onAnnotationUpdated(annotation: Annotation) {
methodChannel.invokeMethod("onAnnotationsChanged", null)
}

override fun onAnnotationRemoved(annotation: Annotation) {
methodChannel.invokeMethod("onAnnotationsChanged", null)
}

override fun onAnnotationZOrderChanged(
pageIndex: Int,
oldOrder: List<Annotation>,
newOrder: List<Annotation>
) {
methodChannel.invokeMethod("onAnnotationsChanged", null)
}
}

pdfFragment?.addOnAnnotationUpdatedListener(annotationUpdatedListener!!)
}

override fun onPageChanged(document: PdfDocument, pageIndex: Int) {
Expand Down Expand Up @@ -80,9 +106,14 @@ class FlutterPdfUiFragmentCallbacks(
}
if (pdfFragment == f) {
pdfFragment?.removeDocumentListener(this)
// Remove the annotation updated listener
if (annotationUpdatedListener != null) {
pdfFragment?.removeOnAnnotationUpdatedListener(annotationUpdatedListener!!)
annotationUpdatedListener = null
}
pdfFragment = null
flutterPdfDocument = null
}
}
}
}
}
4 changes: 2 additions & 2 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.pspdfkit.flutter.pspdfkitExample;
PRODUCT_BUNDLE_IDENTIFIER = com.pspdfkit.flutter.example;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -491,7 +491,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.pspdfkit.flutter.pspdfkitExample;
PRODUCT_BUNDLE_IDENTIFIER = com.pspdfkit.flutter.example;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
51 changes: 36 additions & 15 deletions example/lib/pspdfkit_basic_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,41 @@ class PspdfkitBasicExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: PlatformUtils.isAndroid(),
// Do not resize the the document view on Android or
// it won't be rendered correctly when filling forms.
resizeToAvoidBottomInset: PlatformUtils.isIOS(),
appBar: AppBar(),
body: SafeArea(
top: false,
bottom: false,
child: Container(
padding: PlatformUtils.isAndroid()
? const EdgeInsets.only(top: kToolbarHeight)
: null,
child: PspdfkitWidget(
documentPath: documentPath,
))));
extendBodyBehindAppBar: PlatformUtils.isAndroid(),
// Do not resize the the document view on Android or
// it won't be rendered correctly when filling forms.
resizeToAvoidBottomInset: PlatformUtils.isIOS(),
appBar: AppBar(),
body: SafeArea(
top: false,
bottom: false,
child: Container(
padding: PlatformUtils.isAndroid()
? const EdgeInsets.only(top: kToolbarHeight)
: null,
child: PspdfkitWidget(
documentPath: documentPath,
onAnnotationsChanged: (controller) async {
print("test annotation changed");
print("test controller ${await controller.getZoomScale(0)}");
},
onPspdfkitWidgetCreated: (controller) async {

await controller.setAnnotationConfigurations({
AnnotationTool.inkPen: InkAnnotationConfiguration(
thickness: 2,
color: Colors.black,
)
});
},
configuration: PdfConfiguration(
askForAnnotationUsername: false,
allowAnnotationDeletion: false,
enableAnnotationEditing: true,
),
),
),
),
);
}
}
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Sat Oct 12 10:53:55 PKT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
4 changes: 2 additions & 2 deletions ios/Classes/FlutterPdfDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Foundation

@objc(FlutterPdfDocument)
public class FlutterPdfDocument: NSObject {

// MARK: - Properties
var document: Document?
var messenger: FlutterBinaryMessenger?
var chanel: FlutterMethodChannel?

@objc public init(document: Document, messenger: FlutterBinaryMessenger) {
super.init()
self.document = document
Expand Down
Loading