Submit and save PDF forms to a custom destination
Forms can be submitted to a custom destination using SubmitFormAction
. When creating the action instance, you can provide the form fields, the URI, and the form flags given by the PDF document.
Here’s how to add a button to submit the current values of a form in XFDF format to a custom HTTP endpoint. Other available formats are FDF, HTML, or the whole 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") 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 PSPDFKit 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 @Override public void onDocumentLoaded(@NonNull final PdfDocument document) { super.onDocumentLoaded(document); ... // Retrieve the form field to include in the submit form action. CheckBoxField 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", mutableListOf(checkBoxField), EnumSet.of(SubmitFormAction.SubmitFormActionFlag.XFDF))) .build(); // Ask PSPDFKit 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);
ℹ️ Note: Submitting actions aren’t yet supported by Nutrient Android SDK, but they can be added so that other readers can use them. If you need to execute the created action with Nutrient Android SDK, you can find the relevant information in our customizing the submission method guide.