React-pdf

Edit

Forms

React-pdf includes the ability to use AcroForm-Forms in pdfs. AcroForm is part of interactive pdfs and includes annotations for e.g. text fields, checkboxes. The AcroForm is automatically initialized as soon as one of the form elements is used.

TextInput

The <TextInput /> element represents a text field for inputting single- or multiline text.

Valid props

Prop nameDescriptionTypeDefault
alignDefines the alignment of textStringleft
multilineDefines if the user is allowed to input more than one line of textBooleanfalse
passwordIf set to true the text will be masked with e. g. *Booleanfalse
noSpellIf set to true tells the pdf viewer to not spellcheck the textBooleanfalse
formatDefines the format the textinput should be formatted toTextInputFormattingundefined
fontSizeDefines the font size for the text input. Set to 0 for auto-sizeNumberundefined
maxLengthDefines the maximum number of charactersNumberundefined

See also Common Form Attributes

See it in action →
TextInputFormatting

format is a definition how the value shall be formatted by the viewer. Take into account that not all viewers support this feature because it involves javascript execution.

Prop nameDescriptionTypeDefault
typeDefines the alignment of textTextInputFormatTypeundefined
paramDefines a format for certain typesStringundefined
nDecDefines the number of places after the decimal pointNumberundefined
sepCommaDefines if the seperator shall be a comma or notBooleanfalse
negStyleDefines style for negative numbersStringundefined
currencyDefines the symbol to be placed as currency signStringundefined
currencyPrependIf set to true the currency sign is prependedBooleanfalse
TextInputFormatType

type prop can take one of the following values.

ValueDescription
dateExpects the param prop to be a valid date format.
timeExpects the param prop to be a valid time format.
percentUses the props nDec, sepComma, negStyle, currency, currencyPrepend.
numberUses the props nDec, sepComma, negStyle, currency, currencyPrepend.
zipFormats for the zip-code standard
zipPlus4Formats for the zip+4 standard
phoneFormats for a phone number
ssnFormats for a ssn number

For deeper knowledge into the formatting you might want to look into the pdfkit doc and into the API Reference for Forms Page 119.


Checkbox

The <Checkbox /> element represents one of two states the user can toggle between. Some viewers behave differently based on wether the name prop is set or not and wether there are name duplicates or not. This can result in inconsistencies which makes the name prop recommendable to use and to achieve a consistent result across various viewers.

Valid props

Prop nameDescriptionTypeDefault
backGroundColorIt defines the color of the inside of the checkbox it applies toStringundefined
borderColorDefines the color used to paint the outline of the checkboxStringundefined
checkedIf set to true the checkbox is checkedBooleanfalse
onStateIf set to true tells the pdf viewer to not spellcheck the textStringYes
offStateDefines the format the textinput should be formatted toStringNo
xMarkIf set to true the onState appears as a X otherwise a checkmark is displayedBooleanfalse

See also Common Form Attributes


Select

The <Select /> element represents a dropdown menu for the selection of predefined options.

Valid props

Prop nameDescriptionTypeDefault
editIf set to true allows the user to enter a value in the fieldBooleanfalse
noSpellIf set to true and edit is set to true it tells the pdf viewer to not spellcheck the textBooleanfalse

For more attributes head to Select and List Attributes.


List

The <List /> element represents a scrollable list for the selection of predefined options.

Valid props

For attributes head to Select and List Attributes.


Select and List Attributes

These attributes are shared by the Select and List elements.

Valid props

Prop nameDescriptionTypeDefault
sortDefines if the options shall be sorted alphabeticallyBooleanfalse
multiSelectIf set to true the user is allowed to select multiple optionsBooleanfalse
selectDefines the options to show inside the field as an arrayString[][]

See also Common Form Attributes


FieldSet

The <FieldSet /> element is used to group other form elements together. On the form level this creates a hierarchical structure most important for data extraction and naming clearance. It is fully invisible. The usage of this element is optional and not required by any other element. Because of not being an element on its own the FieldSet is the only element not sharing the common form attributes.

Valid props

Prop nameDescriptionTypeDefault
nameThe name of the FieldSetStringundefined

Common Form Attributes

Common form attributes are attributes that are shared by a variety of elements.

Supported attributes

Prop nameDescriptionTypeDefault
nameDescribes the name of the specific element when submitting the formStringempty
requiredDescribes if the specific element needs to have a value when submitting the formBooleanfalse
noExportIf set to true the specific element is not exported at a form submissionBooleanfalse
readOnlyDefines if the specific element is editable or not. If set to true, the user shall not edit the value.Booleanfalse
valueDefines the value of the specific element. For further information look at the element.String, Numberundefined
defaultValueDescribes what the default state for the value is. Can be used when resetting the form.String, Numberundefined