Effortlessly add signature fields to PDF forms
A form field is a model representation of a visual form element in a document. To enable form field creation, Nutrient exposes a handy set of configuration builders that make the entire process smooth. For more information on the difference between a form field and a form element, see our introduction to forms guide.
A signature form configuration needs at least the page index and the annotation bounding box that will contain the signature form element. Once built, it can be added to a document using FormProvider#addFormElementToPage, which is a suspend function:
val page = 0val rectFSignatureFormConfiguration = RectF( 30f, // left 190f, // top 200f, // right 160f // bottom)val signatureFormConfiguration = SignatureFormConfiguration.Builder(page, rectFSignatureFormConfiguration) .build()lifecycleScope.launch { val signatureFormField = document.formProvider.addFormElementToPage("signaturefield-1", signatureFormConfiguration)}int page = 0;RectF rectFSignatureFormConfiguration = new RectF( 30, // left 190, // top 200, // right 160 // bottom);SignatureFormConfiguration signatureFormConfiguration = new SignatureFormConfiguration.Builder(page, rectFSignatureFormConfiguration) .build();// `addFormElementToPage()` is a suspend function. `runBlocking()` waits for it to finish,// so only call this on a worker thread.try { FormField signatureFormField = BuildersKt.runBlocking( EmptyCoroutineContext.INSTANCE, (scope, continuation) -> getDocument().getFormProvider() .addFormElementToPage("signaturefield-1", signatureFormConfiguration, continuation));} catch (InterruptedException e) { Thread.currentThread().interrupt();}Java can’t call suspend functions directly. See calling asynchronous APIs from Java for the options.
You can add any kind of form field to a document, not just signature form fields. Check out the Android documentation for more information about the Forms API.