Skip to Content
NexPDF

Forms

Let users fill PDF forms and add form fields in an Electron window with NexPDF, and read the filled document back.

English

License module

Filling and creating form fields needs the forms module (Indie tier and above).

This page covers AcroForm fields. For XFA forms (XML Forms Architecture), see XFA forms. To fill a PDF from JSON data with placeholders, see Templates.

Fill a form

The user fills the fields of an open form on the page: text fields take typing in place, check boxes and radio buttons toggle, and lists open their options. Clicking a signature field opens Add signature (Draw, Image or Type) and puts the picture in the field. Each field's keystroke and validate scripts check the value, and calculated fields update as values change. Field appearances are drawn in embedded Unicode fonts, with OpenType shaping and the Unicode bidi algorithm, so Arabic, Hebrew, Indic and other scripts show correctly; right-to-left text without an explicit alignment starts at the right. When the user is done, read the filled document:

const pdf = await openPdfWindow({ file: 'application.pdf', license });
// ... later, for example from your own menu item:
await pdf.save(path.join(app.getPath('documents'), 'application-filled.pdf'));

Add fields

The Forms mode (forms) adds fields by drawing them on the page. Its tools are text, checkbox, radio, listbox, combobox, button, signature and barcode. Choose the ones to offer:

{
  "modeConfig": { "availableModes": ["viewer", "forms"] },
  "formsConfig": { "availableTools": ["text", "checkbox", "signature"] }
}

Pass the configuration as the path of a JSON file; see Viewing pages.

From code

To fill forms in code, for example from a database before showing the window, use the document API in the main process (doc.fillField, doc.fillForm, doc.formFields, as in the Node.js SDK), then open the result with pdf.open(path) or openDocument(engine, bytes):

const { openDocumentFile, openDocument } = require('@nexdevit/nexpdf-electron');

const doc = await openDocumentFile('application.pdf');
doc.fillForm({ 'applicant.name': 'Ana Silva', quantity: '4' });
await openDocument(pdf.engine, doc.toBytes(), 'application.pdf');
pdf.window.webContents.reload();
doc.close();

On this page