Some test text!

Loading...
Guides
Form Builder

Form Builder

Starting in WebViewer 8, you can build and edit forms fields with an interactive form builder that is part of the UI. This form builder mode allows users to add new form fields, and edit existing fields by changing field names, required flags, as well as their size and position in the document. Users are also able to delete form fields. The FormFieldCreationManager also offers several APIs and events that allow developers to run custom logic.

UI

Click Forms in the header, which will activate form building mode.

form-field-mode

Editing Fields

While in this mode, all non-field annotations will be hidden. All existing form fields will be converted into annotations that will serve as placeholders for the actual fields. Any styles currently used by the form field will be carried on to its placeholder, with the exception of radio buttons or signature widgets which do not support styling. This means that if any of your form fields have a transparent border and fill, they will not be immediately visible while in form builder mode. In order to view all your form fields, you can open the notes panel to see all the fields present in the document.

form-builder-panel

In order to view or change the field information for each field, click on the annotation place holder and open the form field edit popup. The popup options will change depending on the type of field being edited.

form-builder-popup

Click Apply Fields to finish editing and apply changes to the fields.

Creating Fields

Currently, the form builder supports the creation six form fields, each with their corresponding tool:

To create a field simply select the tool, and draw an annotation. Using the form field popup you can then specify field name, and required flags.

Text Fields

Text fields can have a default value, as well as support for multi-line via field flags.

text-field-creation

Signature Fields

Starting in WebViewer 8.9, signature fields can be created to accept signatures or initials. Simply choose the required option in the dropdown. Please note that the initials feature must be enabled in order for this option to be displayed. For a sample on how to do this refer to this guide .

Signature widgets that are flagged as requiring initials will apply initials created by the user in the signature modal during the signing process.

signature-field-creation

Radio Fields

In order to logically group radio buttons together, ensure that they all share the same field name.

radio-button-creation

Check Box Field

Check boxes support two field flags: required and read only.

check-box-creation

List and Combo Box Fields

For list and combo box fields you can add as many options as you wish, and re-order them as needed. List box fields also have support for multiselection if this flag is enabled,

list-box-creation

Relevant APIs and events

WebViewer provides some APIs and useful events for customizing the default behaviors.

disableElements

Just like most of the other elements in the viewer, the Form toolbar group has a data-element associated with it, which means you can use disableElements to remove it from the DOM.

WebViewer(...)
  .then(instance => {
    instance.UI.disableElements(['toolbarGroup-Forms']);
  });

Form field creation mode

The FormFieldCreationManager exposes the startFormFieldCreationMode and endFormFieldCreationMode function that can be used to programmatically toggle the form field creation mode. The isInFormFieldCreationMode function can be used to check if WebViewer is currently in the editing mode.

WebViewer(...)
  .then(instance => {
    instance.docViewer.on('annotationsLoaded', () => {
      const formFieldCreationManager = instance.Core.annotationManager.getFormFieldCreationManager();
      formFieldCreationManager.startFormFieldCreationMode();
      formFieldCreationManager.isInFormFieldCreationMode(); // returns true
      // ...
      formFieldCreationManager.endFormFieldCreationMode();
    });
  });

Form field placeholders

The form field placeholder is the annotation that temporarily replaces a form field during form field creation mode. Several helper functions that are related to form field placeholders are also available to use. To see all the available APIs refer to the FormFieldCreationManager documentation.

WebViewer(...)
  .then(instance => {
    instance.Core.annotationManager.on('annotationChanged', (annotations) => {
      const formFieldCreationManager = instance.Core.annotationManager.getFormFieldCreationManager();

      if (!formFieldCreationManager.isInFormFieldCreationMode()) {
        return;
      }

      const formFieldPlaceholders = annotations.filter((annotation) =>
        annotation.isFormFieldPlaceholder()
      );
    });
  });

Events

The formFieldCreationModeStarted and formFieldCreationModeEnded events will be triggered when WebViewer enters and exits form field creation mode. They can be listened to in order to execute custom logic.

WebViewer(...)
  .then(instance => {
    const formFieldCreationManager = instance.Core.annotationManager.getformFieldCreationManager();

    formFieldCreationManager.on('formFieldCreationModeStarted', () => {
      // Form field creation mode started, run some custom logic...
    });

    formFieldCreationManager.on('formFieldCreationModeEnded', () => {
      // Form field creation mode ended, run some custom logic...
    });
  });

Get the answers you need: Support

Upcoming Webinar: PDFTron SDK Tech Review | Nov 29, 2022 at 2 pm ET

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use