diff --git a/example/lib/pspdfkit_form_example.dart b/example/lib/pspdfkit_form_example.dart index 77d744c..6b2a175 100644 --- a/example/lib/pspdfkit_form_example.dart +++ b/example/lib/pspdfkit_form_example.dart @@ -85,7 +85,7 @@ class _PspdfkitFormExampleWidgetState extends State { ElevatedButton( onPressed: () async { await view - .getFormFieldValue('Name_Last') + .getFormFieldProperties('Birthdate') .then((formFieldValue) async { await showDialog( context: context, @@ -93,8 +93,9 @@ class _PspdfkitFormExampleWidgetState extends State { AlertDialog( title: const Text( 'Form Field Value'), - content: - Text(formFieldValue ?? ''), + content: Text(formFieldValue + ?.toString() ?? + ''), actions: [ TextButton( onPressed: () { diff --git a/ios/Classes/PspdfkitFlutterHelper.m b/ios/Classes/PspdfkitFlutterHelper.m index 67cb1e6..8d34d53 100644 --- a/ios/Classes/PspdfkitFlutterHelper.m +++ b/ios/Classes/PspdfkitFlutterHelper.m @@ -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) { @@ -453,6 +456,37 @@ + (id)getFormFieldValueForFieldWithFullyQualifiedName:(NSString *)fullyQualified return formFieldValue; } ++(id) getFormFieldPropertiesWithFullyQualifiedName:(NSString *) fullyQualifiedName forViewControlelr: (PSPDFViewController *) pdfViewController { + + 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 *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 { diff --git a/lib/src/widgets/pspdfkit_widget_controller.dart b/lib/src/widgets/pspdfkit_widget_controller.dart index 79efaf0..90b6d93 100644 --- a/lib/src/widgets/pspdfkit_widget_controller.dart +++ b/lib/src/widgets/pspdfkit_widget_controller.dart @@ -19,6 +19,8 @@ abstract class PspdfkitWidgetController { /// Gets the form field value by specifying its fully qualified name. Future getFormFieldValue(String fullyQualifiedName); + Future getFormFieldProperties(String fullyQualifiedName); + /// Applies Instant document JSON to the presented document. Future applyInstantJson(String annotationsJson); diff --git a/lib/src/widgets/pspdfkit_widget_controller_native.dart b/lib/src/widgets/pspdfkit_widget_controller_native.dart index 2e9af31..255a146 100644 --- a/lib/src/widgets/pspdfkit_widget_controller_native.dart +++ b/lib/src/widgets/pspdfkit_widget_controller_native.dart @@ -169,4 +169,10 @@ class PspdfkitWidgetControllerNative extends PspdfkitWidgetController { throw Exception('Error getting zoom scale: $error'); }); } + + @override + Future getFormFieldProperties(String fullyQualifiedName) { + return _channel.invokeMethod('getFormFieldProperties', + {'fullyQualifiedName': fullyQualifiedName}); + } } diff --git a/lib/src/widgets/pspdfkit_widget_controller_web.dart b/lib/src/widgets/pspdfkit_widget_controller_web.dart index 275aabe..fd0efac 100644 --- a/lib/src/widgets/pspdfkit_widget_controller_web.dart +++ b/lib/src/widgets/pspdfkit_widget_controller_web.dart @@ -121,4 +121,10 @@ class PspdfkitWidgetControllerWeb extends PspdfkitWidgetController { Future getZoomScale(int pageIndex) { return pspdfkitInstance.getZoomScale(pageIndex); } + + @override + Future getFormFieldProperties(String fullyQualifiedName) { + // TODO: implement getFormFieldPRoperties + throw UnimplementedError(); + } }