Submit and Save PDF Forms to External Destinations

Form submission is a PDF action performed on a form element in a PDF document. It’s a method of taking user input from a form described in a PDF and sending it to a given location. The sent data can include all the form fields in the document or just a subset of them. Form submission is usually configured in the PDF itself to be triggered when a submit button is tapped. Form submission actions are represented by the SubmitFormAction class.

Submission Method

PSPDFKit supports default submission types — for example, GET and POST HTML requests. The chosen method will depend on the given PDF document and the flags applied in the form submit action. The URL used for this submission is also embedded in the form submit action information. The data will be passed in the body of the request in the format required (this will be covered in the following section).

If a custom submission method is required, it’s possible to retrieve the values of the form fields and use the form submission delegate to catch a submit button press. This is described in our Submit Forms to a Custom Destination guide.

Format

It’s possible to send data in a variety of formats to allow the recipient to parse the data in a known format. This format is provided by the action flags within the PDF document. PSPDFKit will parse these and choose the format based on this selection.

FDF

This is the default format for form submissions, and it’s described as a subset of PDF. The structure of FDF is essentially the same as a PDF document, although only the form elements are present. This format can be used to import data back into a PDF at a later date. Adobe also provides an FDF Toolkit, which can be used to parse the FDF format on the server side or elsewhere.

The following shows an example of the FDF format. filePath will reflect the path where the file was sent from. Here you can also see Fields with the given key (TextField1) and value (TestText):

%FDF-1.2
1 0 obj
<<
	/FDF <<
		/F <<
			/F(${filePath})/Type/Filespec/UF(${filePath})
		>>
		/Fields [<</T(TextField1)/V(TestText)>>]
	>>
>>
endobj

trailer
<</Root 1 0 R>>
%%EOF

HTML

The HTML format is similar to what you’d find in the query portion of a URL, but it’s placed in the body of the request. This is the same format used by forms in HTML webpages. The form fields will be converted to key-value pairs, with the name being the ID of the form field and the value being the user input. This format abides by the HTML 4.01 Specification.

The body of the HTML request will hold the values sent from the form. The following shows how two form fields will be generated — note that it’s delimited by an ampersand. This can be easily parsed by most web server technologies:

TextField1=TestText&TextField2=TestText2

XFDF

XFDF is similar to FDF, but it’s represented in an XML-like format. This is a standard provided by Adobe and therefore supported by Adobe Acrobat and various other third-party products. See our XFDF Support guide for more details.

XFDF will output a file with XML notation. It’ll hold a collection of fields, each of which can have a collection of values. Here you can see the form field TextField1 has a value element of TestText:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/">
	<fields>
		<field name="TextField1">
			<value>TestText</value>
		</field>
	</fields>
</xfdf>

PDF

It’s also possible to submit an entire PDF document. This option is useful when the recipient has no reference to the original document. Seeing as the whole PDF is transmitted with this format, it’s a highly wasteful process, especially when submitting complex and large documents.