Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEMO- Form Field properties JSON #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 4 additions & 3 deletions example/lib/pspdfkit_form_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ class _PspdfkitFormExampleWidgetState extends State<PspdfkitFormExampleWidget> {
ElevatedButton(
onPressed: () async {
await view
.getFormFieldValue('Name_Last')
.getFormFieldProperties('Birthdate')
.then((formFieldValue) async {
await showDialog<AlertDialog>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text(
'Form Field Value'),
content:
Text(formFieldValue ?? ''),
content: Text(formFieldValue
?.toString() ??
''),
actions: [
TextButton(
onPressed: () {
Expand Down
34 changes: 34 additions & 0 deletions ios/Classes/PspdfkitFlutterHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ + (void)processMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
} else if ([@"getFormFieldValue" isEqualToString:call.method]) {
NSString *fullyQualifiedName = call.arguments[@"fullyQualifiedName"];
result([PspdfkitFlutterHelper getFormFieldValueForFieldWithFullyQualifiedName:fullyQualifiedName forViewController:pdfViewController]);
} else if([@"getFormFieldProperties" isEqualToString:call.method]){
NSString *fullyQualifiedName = call.arguments[@"fullyQualifiedName"];
result([PspdfkitFlutterHelper getFormFieldPropertiesWithFullyQualifiedName:fullyQualifiedName forViewControlelr:pdfViewController]);
} else if ([@"applyInstantJson" isEqualToString:call.method]) {
NSString *annotationsJson = call.arguments[@"annotationsJson"];
if (annotationsJson.length == 0) {
Expand Down Expand Up @@ -453,6 +456,37 @@ + (id)getFormFieldValueForFieldWithFullyQualifiedName:(NSString *)fullyQualified
return formFieldValue;
}

+(id) getFormFieldPropertiesWithFullyQualifiedName:(NSString *) fullyQualifiedName forViewControlelr: (PSPDFViewController *) pdfViewController {
Copy link
Collaborator Author

@mutumbakato mutumbakato Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get form Fiel properties by fullyQualifiedName as JSON.


if (fullyQualifiedName == nil || fullyQualifiedName.length == 0) {
FlutterError *error = [FlutterError errorWithCode:@"" message:@"Fully qualified name may not be nil or empty." details:nil];
return error;
}

PSPDFDocument *document = pdfViewController.document;
PSPDFAnnotation *annotation = nil;

for (PSPDFFormElement *formElement in document.formParser.forms) {
if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) {
annotation = formElement.formField.annotations.firstObject;
break;
}
}

if (annotation == nil ){
FlutterError *error = [FlutterError errorWithCode:@"" message:[NSString stringWithFormat:@"Error while searching for a form element with name %@.", fullyQualifiedName] details:nil];
return error;
}

NSError *error = nil;
NSData *annotationData = [annotation generateInstantJSONWithError:&error];
NSDictionary <NSString *, NSString *> *uuidDict = @{@"uuid" : annotation.uuid};
NSMutableDictionary *annotationDictionary = [[NSJSONSerialization JSONObjectWithData:annotationData options:kNilOptions error:NULL] mutableCopy];
[annotationDictionary addEntriesFromDictionary:uuidDict];

return annotationDictionary;
}

# pragma mark - Annotation Processing

+ (id)processAnnotationsOfType:(NSString *)type withProcessingMode:(NSString *)processingMode andDestinationPath:(NSString *)destinationPath forViewController:(PSPDFViewController *)pdfViewController {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/widgets/pspdfkit_widget_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ abstract class PspdfkitWidgetController {
/// Gets the form field value by specifying its fully qualified name.
Future<String?> getFormFieldValue(String fullyQualifiedName);

Future<dynamic> getFormFieldProperties(String fullyQualifiedName);

/// Applies Instant document JSON to the presented document.
Future<bool?> applyInstantJson(String annotationsJson);

Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/pspdfkit_widget_controller_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,10 @@ class PspdfkitWidgetControllerNative extends PspdfkitWidgetController {
throw Exception('Error getting zoom scale: $error');
});
}

@override
Future getFormFieldProperties(String fullyQualifiedName) {
return _channel.invokeMethod('getFormFieldProperties',
<String, dynamic>{'fullyQualifiedName': fullyQualifiedName});
}
}
6 changes: 6 additions & 0 deletions lib/src/widgets/pspdfkit_widget_controller_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,10 @@ class PspdfkitWidgetControllerWeb extends PspdfkitWidgetController {
Future<double> getZoomScale(int pageIndex) {
return pspdfkitInstance.getZoomScale(pageIndex);
}

@override
Future getFormFieldProperties(String fullyQualifiedName) {
// TODO: implement getFormFieldPRoperties
throw UnimplementedError();
}
}