# pdf-viewer-form-designer

> PDF viewer adds configurable form fields to the current page with a field-type dropdown and document-load gating.

**Framework:** react  **Component:** PdfViewer  **Variant:** form-designer

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/react/js/pdf-viewer-form-designer.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-dropdowns @syncfusion/ej2-react-pdfviewer
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/pdf-viewer-form-designer/PdfViewer.jsx

```jsx
import { useRef, useState } from 'react';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import {
    Annotation, BookmarkView, FormDesigner, FormFields, Inject, LinkAnnotation, Magnification,
    Navigation, PageOrganizer, PdfViewerComponent, Print, TextSearch, TextSelection, ThumbnailView,
    Toolbar
} from '@syncfusion/ej2-react-pdfviewer';

const fieldTypes = [
    { text: 'Textbox', value: 'Textbox' },
    { text: 'Password', value: 'Password' },
    { text: 'Checkbox', value: 'CheckBox' },
    { text: 'Radio button', value: 'RadioButton' },
    { text: 'Dropdown', value: 'DropDown' },
    { text: 'List box', value: 'ListBox' },
    { text: 'Signature', value: 'SignatureField' },
    { text: 'Initial', value: 'InitialField' },
    { text: 'Button', value: 'ButtonField' }
];

const fieldTypeFields = { text: 'text', value: 'value' };

function FormDesignerSample() {
    const viewerRef = useRef(null);
    const fieldNumber = useRef(0);
    const [fieldType, setFieldType] = useState('Textbox');
    const [isDocumentLoaded, setIsDocumentLoaded] = useState(false);

    const addFormField = () => {
        const viewer = viewerRef.current;
        if (!viewer) {
            return;
        }

        const currentField = fieldNumber.current++;
        const settings = {
            name: `${fieldType}_${currentField + 1}`,
            pageNumber: viewer.currentPageNumber,
            bounds: {
                X: 100 + (currentField % 2) * 240,
                Y: 120 + (Math.floor(currentField / 2) % 8) * 55,
                Width: 200,
                Height: 32
            },
            ...(fieldType === 'DropDown' || fieldType === 'ListBox'
                ? {
                    options: [
                        { itemName: 'Option 1', itemValue: 'Option 1' },
                        { itemName: 'Option 2', itemValue: 'Option 2' },
                        { itemName: 'Option 3', itemValue: 'Option 3' }
                    ]
                }
                : {})
        };

        viewer.formDesigner.addFormField(fieldType, settings);
    };

    return (
        <div className='control-section'>
            <div
                role='group'
                aria-label='Form field controls'
                style={{ display: 'flex', alignItems: 'flex-end', gap: '12px', marginBottom: '12px' }}
            >
                <div style={{ width: '220px' }}>
                    <label htmlFor='form-field-type' style={{ display: 'block', marginBottom: '4px' }}>
                        Form Field Type
                    </label>
                    <DropDownListComponent
                        id='form-field-type'
                        dataSource={fieldTypes}
                        fields={fieldTypeFields}
                        value={fieldType}
                        change={(event) => {
                            if (typeof event.value === 'string') {
                                setFieldType(event.value);
                            }
                        }}
                        enabled={isDocumentLoaded}
                        width='100%'
                    />
                </div>
                <button
                    className='e-btn e-primary'
                    type='button'
                    onClick={addFormField}
                    disabled={!isDocumentLoaded}
                >
                    Add Form Field
                </button>
            </div>
            <p role='status'>
                {isDocumentLoaded
                    ? 'Adds the selected field to the currently displayed page.'
                    : 'Loading PDF document...'}
            </p>
            <PdfViewerComponent
                id='form-designer-viewer'
                ref={viewerRef}
                documentPath='https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf'
                resourceUrl='https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib'
                documentLoad={() => setIsDocumentLoaded(true)}
                style={{ height: '640px' }}
            >
                <Inject services={[
                    Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
                    Print, TextSelection, TextSearch, Annotation, FormFields, FormDesigner, PageOrganizer
                ]} />
            </PdfViewerComponent>
        </div>
    );
}

export default FormDesignerSample;

```
