---
title: "Extract PDF form data on Android"
canonical_url: "https://www.nutrient.io/guides/android/forms/extract-form-data/"
md_url: "https://www.nutrient.io/guides/android/forms/extract-form-data.md"
last_updated: "2026-05-23T00:08:17.987Z"
description: "Learn how to extract data from PDF form fields on Android using XFDF and Instant JSON formats with easy-to-follow code examples."
---

# Easy steps to extract PDF form data on Android

The data that users fill in PDF form fields can be extracted programmatically or serialized to the XFDF format or the Instant JSON format.

## Extracting form data programmatically

To extract data in a custom format, you can read the values from the form fields, which are accessible using a document’s [form provider](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.forms/-form-provider/index.html):

### KOTLIN

```kotlin

// Get a reference to the form fields in the document.
val checkbox = document.formProvider.getFormFieldWithFullyQualifiedName("CheckBox 1") as CheckBoxFormField
// Extract the value.
val selected = checkbox.formElement.isSelected

```

### JAVA

```java

// Get a reference to the form fields in the document.
final CheckBoxFormField checkbox = (CheckBoxFormField) document.getFormProvider().getFormFieldWithFullyQualifiedName("CheckBox 1");
// Extract the value.
final boolean selected = checkbox.getFormElement().isSelected();

```

## Extracting form data as XFDF

You can export the values of form fields from a document as an [XFDF](https://www.nutrient.io/guides/android/importing-exporting/xfdf-support.md) file using [`XfdfFormatter`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.formatters/-xfdf-formatter/index.html), like this:

### KOTLIN

```kotlin

// Create a temporary file for the XFDF output.
val xfdfOutputTempFile = File.createTempFile("tmp-", "ExtractedFormFields.xfdf")
xfdfOutputTempFile.deleteOnExit()

// Write data into it.
XfdfFormatter.writeXfdf(document, emptyList(), document.formProvider.formFields, FileOutputStream(xfdfOutputTempFile))

```

### JAVA

```java

// Create a temporary file for the XFDF output.
final File xfdfOutputTempFile = File.createTempFile("tmp-", "ExtractedFormFields.xfdf");
xfdfOutputTempFile.deleteOnExit();

// Write data into it.
XfdfFormatter.writeXfdf(document, emptyList(), document.getFormProvider().getFormFields(), new FileOutputStream(xfdfOutputTempFile));

```

## Extracting form data as Instant JSON

[Instant JSON](https://www.nutrient.io/guides/android/json.md) is optimized for annotations. However, generating Instant JSON from a document will also include form field values.

Since exporting Instant JSON from a document produces a diff between the in-memory document and the document saved on disk, you should ensure auto-save is disabled and that you’re not saving the document at any other time. Disable auto-save by configuring a `PdfActivityConfiguration.Builder`, like this:

### KOTLIN

```kotlin

configuration.autosaveEnabled(false).build()

```

### JAVA

```java

configuration.autosaveEnabled(false).build();

```

You can export Instant JSON as a file using [`DocumentJsonFormatter#exportDocumentJson(PdfDocument, OutputStream)`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.formatters/-document-json-formatter/export-document-json.html), like this:

### KOTLIN

```kotlin

val outputStream = ByteArrayOutputStream()
DocumentJsonFormatter.exportDocumentJson(document, outputStream)

```

### JAVA

```java

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DocumentJsonFormatter.exportDocumentJson(document, outputStream);

```

Note that this Instant JSON will also include the visual properties of the form element, such as text color and border style, as well as other annotations, such as text highlights and drawings.

Exporting Instant JSON from an [`Annotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-annotation/index.html) using the [`toInstantJson()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-annotation/to-instant-json.html) function isn’t appropriate for form field values because this models the properties of the form element (text color, border style, etc.) and doesn’t include the value of a form field associated with a form element.
---

## Related pages

- [Flatten PDF form fields on Android](/guides/android/forms/flatten.md)
- [PDF form library for Android](/guides/android/forms.md)
- [Validate PDF forms on Android with JavaScript](/guides/android/forms/javascript-validation.md)
- [Explore flexible PDF form actions on Android](/guides/android/forms/pdf-actions-support.md)

