Submit and save PDF forms to a custom destination
Use SubmitFormAction to define a form submission to a custom destination. Provide these parameters when creating the action:
- The destination URI
- The form fields to include
- The submission flags, including the format
The following example adds a button that defines an XFDF submission to a custom HTTP endpoint. Other formats include FDF, HTML, and the entire PDF.
override fun onDocumentLoaded(document: PdfDocument) { super.onDocumentLoaded(document) // Retrieve the form field to include in the submit form action. val checkBoxField = document?.formProvider?.getFormFieldWithFullyQualifiedName("checkboxfield-1") ?: return
val rectFPushButtonFormConfiguration = RectF(30f, 350f, 120f, 260f) val colorBitmap = Bitmap.createBitmap(500, 300, Bitmap.Config.ARGB_8888) val canvas = Canvas(colorBitmap) // Just use a red fill so the button is visible. canvas.drawColor(Color.RED)
// Create the button form element (annotation). val pushButtonFormConfiguration = PushButtonFormConfiguration.Builder( 0, rectFPushButtonFormConfiguration, colorBitmap ) // Create the action and set the submission format to XFDF. .setAction(SubmitFormAction( "https://example.com/wherever-you-want-to-send-the-form", mutableListOf(checkBoxField), EnumSet.of(SubmitFormAction.SubmitFormActionFlag.XFDF))) .build()
// Ask Nutrient to create the form field and add it to the document. This will also add the form element to the document. // The `fullyQualifiedName` must not be the same as an existing form field, but otherwise can be whatever you like. document?.formProvider?.addFormElementToPage("pushbuttonfield-1", pushButtonFormConfiguration)}@UiThread@Overridepublic void onDocumentLoaded(@NonNull final PdfDocument document) { super.onDocumentLoaded(document); // Retrieve the form field to include in the submit form action. FormField checkBoxField = document.getFormProvider().getFormFieldWithFullyQualifiedName("checkboxfield-1");
RectF rectFPushButtonFormConfiguration = new RectF(30f, 350f, 120f, 260f); Bitmap colorBitmap = Bitmap.createBitmap(500, 300, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(colorBitmap); // Just use a red fill so the button is visible. canvas.drawColor(Color.RED);
// Create the button form element (annotation). PushButtonFormConfiguration pushButtonFormConfiguration = new PushButtonFormConfiguration.Builder( 0, rectFPushButtonFormConfiguration, colorBitmap ) // Create the action and set the submission format to XFDF. .setAction(new SubmitFormAction( "https://example.com/wherever-you-want-to-send-the-form", Collections.singletonList(checkBoxField), EnumSet.of(SubmitFormAction.SubmitFormActionFlag.XFDF))) .build();
// Ask Nutrient to create the form field and add it to the document. This will also add the form element to the document. // The `fullyQualifiedName` must not be the same as an existing form field, but otherwise can be whatever you like. document.getFormProvider().addFormElementToPage("pushbuttonfield-1", pushButtonFormConfiguration);}Nutrient Android SDK can add submission actions for other readers, but it doesn’t execute them by default. To implement submission, refer to the customizing the submission method guide.