How can I help you?
Customize the appearance of PDF Form Fields in React PDF Viewer
25 Feb 20266 minutes to read
Styling customizes appearance only (font, color, alignment, border, background, indicator text).
Customize appearance of form fields using the UI
Use the Properties panel to adjust:
- Font family and size, text color, and alignment
- Border color and thickness
- Background color
Customize appearance of form fields programmatically
Use updateFormField() to apply styles:
import * as ReactDOM from 'react-dom/client';
import React, { useRef } from 'react';
import './index.css';
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, Annotation, TextSearch, FormFields, FormDesigner, Inject } from '@syncfusion/ej2-react-pdfviewer';
export function App() {
const viewerRef = useRef(null);
const updateTextboxStyle = () => {
const fields = viewerRef.current?.retrieveFormFields?.() || [];
const tb = fields.find((f) => f.name === 'First Name') || fields[0];
if (tb) {
viewerRef.current.formDesignerModule.updateFormField(tb, {
value: 'John',
fontFamily: 'Courier',
fontSize: 12,
color: 'black',
borderColor: 'black',
backgroundColor: 'white',
alignment: 'Left',
thickness: 2
});
}
};
return (
<div className='control-section'>
<button onClick={updateTextboxStyle}>Update Textbox Style</button>
<PdfViewerComponent
ref={viewerRef}
id="container"
documentPath="https://cdn.syncfusion.com/content/pdf/form-designer.pdf"
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib"
style=
>
<Inject services={[Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]} />
</PdfViewerComponent>
</div>
);
}
const root = ReactDOM.createRoot(document.getElementById('sample'));
root.render(<App />);Set Default Styles for New Form Fields
Define defaults so fields added from the toolbar inherit styles.
import * as ReactDOM from 'react-dom/client';
import React, { useEffect, useRef } from 'react';
import './index.css';
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, Annotation, TextSearch, FormFields, FormDesigner, Inject } from '@syncfusion/ej2-react-pdfviewer';
export function App() {
const viewerRef = useRef(null);
useEffect(() => {
if (viewerRef.current) {
viewerRef.current.textFieldSettings = {
name: 'Textbox',
isReadOnly: false,
visibility: 'visible',
isRequired: false,
isPrint: true,
tooltip: 'Textbox',
thickness: 4,
value: 'Textbox',
fontFamily: 'Courier',
fontSize: 10,
fontStyle: 'None',
color: 'black',
borderColor: 'black',
backgroundColor: 'White',
alignment: 'Left',
maxLength: 0,
isMultiline: false
};
}
}, []);
return (
<div className='control-section'>
<PdfViewerComponent
ref={viewerRef}
id="container"
documentPath="https://cdn.syncfusion.com/content/pdf/form-designer.pdf"
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib"
style=
>
<Inject services={[Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]} />
</PdfViewerComponent>
</div>
);
}
const root = ReactDOM.createRoot(document.getElementById('sample'));
root.render(<App />);