Programmatic Form Filling
PSPDFKit for Web supports the AcroForm standard and can view and fill forms inside the Instance
.
Forms are an optional component that can be licensed. If not licensed, forms will simply be invisible. Forms can be manually disabled by setting Configuration#disableForms
to true
as part of the load()
call.
You can also modify and query forms in code — for example, filling out forms programmatically:
1 2 3 4 5 6 7 8 9 10 | const formFields = await instance.getFormFields(); // Update the value of all text form fields. const updatedFormFieldValues = formFields .filter(formField => (formField instanceof PSPDFKit.FormFields.TextFormField) ) .reduce((o, formField) => o[formField.name] = "New Value", {}); instance.setFormFieldValues(updatedFormFieldValues); |
1 2 3 4 5 6 7 8 9 10 | instance.getFormFields().then(function(formFields) { // Update the value of all text form fields. var updatedFormFieldValues = {}; formFields.forEach(function(formField) { if (formField instanceof PSPDFKit.FormFields.TextFormField) { updatedFormFieldValues[formField.name] = "New Value"; } }); instance.setFormFieldValues(updatedFormFieldValues); }); |
The argument for Instance#setFormFieldValues
must be a simple JavaScript object, where the keys refer to the FormField#name
of the form field that you want to update, and the value is either null
, string
, or Array<string>
, depending upon the type of the FormField
.