React PDF form library

Nutrient Web SDK is a JavaScript library for filling, reading, creating, and editing PDF AcroForms. It’s fully compatible with React and offers developers an API for programmatic access to PDF form objects, as well as a beautiful user interface (UI) for form filling in any React-based web app.

Try for free Launch demo

Nutrient SDKs are trusted by world’s most popular applications, including Autodesk, Disney, UBS, Dropbox, IBM, and Lufthansa. Nutrient’s powerful solutions enable seamless integration of PDF editing features into your applications, delivering reliability and efficiency to world-class enterprises.

Key capabilities

  • User friendly interface — Fill forms easily with a prebuilt UI

  • Programmatic access — Read, write, and modify PDF form data

  • Database integration — Import/export form data seamlessly

  • Signatures — Add electronic signature fields

  • Custom permissions — Control user interactions with form fields

  • High-performance rendering — Ensure smooth form handling in React-based web applications

Build and manage PDF forms in React

PDF forms allow users to input data digitally, replacing traditional paper forms. With Nutrient Web SDK, developers can seamlessly integrate PDF form functionality into React-based web applications, enabling form creation, filling, data extraction, and more.

This guide provides a comprehensive tutorial for working with React-based PDF forms, including code examples and best practices.

What are PDF forms?

PDF forms are interactive documents that allow users to enter data. Unlike static PDFs, these forms include fillable fields such as text boxes, checkboxes, dropdowns, and signature fields. For more information, see understanding the benefits of PDF forms.

Supported PDF form fields

Nutrient Web SDK supports various PDF form fields, including:

  • Text fields (for entering text)

  • Checkboxes (for multiple-choice selections)

  • Radio buttons (for selecting one option)

  • Push buttons (for triggering an action when clicked)

  • List boxes (for choosing multiple options from a predefined list)

  • Combo boxes (for choosing a single option from a predefined list)

  • Signature fields (for signing PDFs)

For more information, see supported PDF form fields.

Supported data formats

PDF forms can store and retrieve data in multiple formats, including:

  • XFDF (XML forms data format)

  • JSON (for web applications)

For more information, see PDF form elements and data formats.

Fill PDF forms programmatically

Nutrient Web SDK offers multiple options for filling form fields programmatically, each with a different set of tradeoffs.

  • Using Web SDK with Document Engine — For persisting, restoring, and synchronizing the form field values across multiple devices without needing to build it yourself.

  • XFDF — For exporting to or importing from other readers.

  • Instant JSON — For the most efficient way to export or import changes made.

  • Manual API — For complete control over extracting and saving the values of the forms.

For example, when using Web SDK with Document Engine, when a document is opened from Document Engine, the latest form field values are immediately loaded.

PSPDFKit.load({
  container: "#pspdfkit",
  documentId: "DOCUMENT_ID_GOES_HERE",
  authPayload: { jwt: "YOUR_JWT_GOES_HERE" },
  instant: true // Sync changes between users who have same document open.
  // ...
});

For more information, see fill PDF forms programmatically.

Flatten PDF forms

Flattening a form ensures users can no longer edit the fields:

const content = await instance.exportPDF({ flatten: true });
console.log(content); // => ArrayBuffer of document with flattened form fields

For more information, see flatten dynamic PDF forms.

Add a signature field to a PDF form

You can add a signature form field, which can then be used as a placeholder for electronic signatures:

const widget = new PSPDFKit.Annotations.WidgetAnnotation({
  id: PSPDFKit.generateInstantId(),
  pageIndex: 0,
  boundingBox: new PSPDFKit.Geometry.Rect({
    left: 200,
    top: 300,
    width: 150,
    height: 75
  }),
  formFieldName: "my signature form field"
});
const formField = new PSPDFKit.FormFields.SignatureFormField({
  name: "my signature form field",
  annotationIds: new PSPDFKit.Immutable.List([widget.id])
});
await instance.create([widget, formField]);

For more information, see adding a signature field to a PDF form.

Import data into PDF forms from a database

You can populate forms with external data sources such as databases. For example, assume your backend application exposes a /profile endpoint that returns the current user’s profile information, including the first name and the last name.

If you want to prefill the first name and the last name in the document the user opens, insert the form field values into the Instant JSON object and import it when the document is opened:

// This loads the profile information from your server which, in turn, imports it from the database.
const profileResponse = await fetch(
  "https://your-server.example.com/profile"
);
const { firstName, lastName } = await profileResponse.json();
// Insert the form field values into Instant JSON.
const instantJSON = {
  format: "https://pspdfkit.com/instant-json/v1",
  formFieldValues: [
    {
      v: 1,
      type: "pspdfkit/form-field-value",
      name: "firstNameField",
      value: firstName
    },
    {
      v: 1,
      type: "pspdfkit/form-field-value",
      name: "lastNameField",
      value: lastName
    }
  ]
};
// Open a document and immediately import Instant JSON into it.
const instance = PSPDFKit.load({
  instantJSON: instantJSON /* required options */
});

For more information, see import data into PDFs from a database.

Fill PDF form fields using the built-in UI

Nutrient Web SDK provides a user-friendly form filling UI out of the box. For example, if the Form Creator component is present in your license, pressing a form field will select it and enable moving and resizing it:

instance.setViewState((viewState) =>
  viewState.set("formDesignMode", true)
);

For more information, see fill PDF form fields using viewer UI.

Extract data from PDF form fields

You can extract form data in Instant JSON or other formats:

const instantJSON = await instance.exportInstantJSON();

const formFieldValues = instantJSON.formFieldValues;
console.log(formFieldValues); // [{"name":"Form Field","type":"pspdfkit/form-field-value","v":1]

For more information, see extract data from PDF form fields.

Read PDF form fields

Retrieve form field names, types, and values programmatically:

const formFields = await instance.getFormFields();
console.log(formFields.size);

For more information, see read PDF form fields using JavaScript.

Additional PDF form functionalities

FAQ

What is Nutrient Web SDK? Nutrient Web SDK is a powerful JavaScript library that enables developers to fill, create, and edit PDF AcroForms in web applications.
How can forms be filled using Nutrient Web SDK? Forms in PDF documents can be filled programmatically using APIs or interactively through Nutrient Web SDK’s intuitive UI.
Can I create PDF forms from scratch with Nutrient Web SDK? Yes, Nutrient Web SDK allows you to create fillable PDF forms and fields from scratch using developer APIs or the drag-and-drop form creator tool.
Can I customize the appearance of form fields in Nutrient Web SDK? Absolutely! Nutrient Web SDK offers styling options to customize the appearance of form fields, including colors, borders, backgrounds, and widths.
Does Nutrient Web SDK support form validation? Yes, Nutrient Web SDK supports JavaScript-based form validation to ensure the accuracy and reliability of form field inputs.

Free trial

Start your free trial for unlimited access and expert support.