Foxit PDF SDK for Android

How to Fill and Manage Forms with Foxit PDF SDK for Android

Form (AcroForm) is a collection of fields for gathering information interactively from the user. Foxit PDF SDK provides APIs to view and edit form fields programmatically. Form fields are commonly used in PDF documents to gather data. The Form class offers functions to retrieve form fields or form controls, import/export form data and other features, for example:

  • To retrieve form fields, please use functions Form.getFieldCount and Form.getField.
  • To retrieve form controls from a PDF page, please use functions Form.getControlCount and Form.getControl.
  • To import form data from an XML file, please use function Form.importFromXML; to export form data to an XML file, please use function Form.exportToXML.
  • To retrieve form filler object, please use function Form.getFormFiller.

To import form data from a FDF/XFDF file or export such data to a FDF/XFDF file, please refer to functions PDFDoc.importFromFDF and PDFDoc.exportToFDF.

Example:

How to import and export form data from or to a XML file

import com.foxit.sdk.PDFViewCtrl;
import com.foxit.sdk.common.Constants;
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.pdf.interform.Form;
...

// Check if the document has a form.
try {
  String pdfpath = "xxx/Sample.pdf";
  PDFDoc doc = new PDFDoc(pdfpath);
  boolean hasForm = doc.hasForm();
  if(hasForm) {

// Create a form object from document.
  Form form = new Form(doc);

// Export the form data to a XML file.
  form.exportToXML("/somewhere/export.xml");
// Or import the form data from a XML file.
  form.importFromXML("/somewhere/export.xml");
  }
}catch (Exception e) {}

Updated on May 29, 2019

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: