Skip to content

Commit 31381e3

Browse files
994681: Updated Form Designer functionalities UG.
1 parent b3b218e commit 31381e3

File tree

12 files changed

+998
-102
lines changed

12 files changed

+998
-102
lines changed

Document-Processing-toc.html

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,29 +1351,34 @@
13511351
</ul>
13521352
</li>
13531353
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/interaction-mode">Interaction Mode</a></li>
1354-
<li>Form Designer
1355-
<ul>
1356-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/create-programmatically">Create form fields programmatically</a></li>
1357-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/create-with-user-interface-interaction">Create form fields with UI interaction</a></li>
1358-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/toolbar-customization/form-designer-toolbar">Form Designer Toolbar</a></li>
1359-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-field-events">Form Field events</a></li>
1360-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/how-to/custom-fonts-ts">Custom fonts</a></li>
1361-
</ul>
1362-
</li>
1363-
<li>Form Fields
1354+
<li>Forms
13641355
<ul>
13651356
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/overview">Overview</a></li>
13661357
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-filling">Fill form fields</a></li>
13671358
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/toolbar-customization/form-designer-toolbar">Form Designer Toolbar</a></li>
1368-
<ul>Create, Edit, Style and Remove Form Fields
1369-
<li></li>
1370-
<li></li>
1371-
</ul>
1372-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-field-events">Form Field events</a></li>
1359+
<li>Create, Edit, Style and Remove Form Fields
1360+
<ul>
1361+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/Create-edit-Style-del-formFields/create-formfields">Create form fields</a></li>
1362+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/Create-edit-Style-del-formFields/edit-formfields">Edit form fields</a></li>
1363+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/Create-edit-Style-del-formFields/style-formfields">Style form fields</a></li>
1364+
</ul>
1365+
</li>
1366+
<li>Import/Export form data
1367+
<ul>
1368+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/import-export-formfields/import-formfields">Import form data</a></li>
1369+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/import-export-formfields/export-formfields">Export form data</a></li>
1370+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/import-export-formfields/import-export-events">Import/Export events</a></li>
1371+
</ul>
1372+
</li>
1373+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/custom-data">Add custom data in form fields</a></li>
1374+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/group-formfields">Grouping form fields</a></li>
1375+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-constrain">Form constrains</a></li>
1376+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-validation">Form Validation</a></li>
13731377
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/how-to/custom-fonts-ts">Custom fonts</a></li>
1378+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-field-events">Form Field events</a></li>
1379+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/formfields-api">APIs</a></li>
13741380
</ul>
13751381
</li>
1376-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-filling">Form Filling</a></li>
13771382
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/organize-pdf">Organize Pages</a>
13781383
<ul>
13791384
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/organize-pages/overview">Overview</a></li>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
layout: post
3+
title: Add custom data to form fields in the TypeScript PDF Viewer component | Syncfusion
4+
description: Learn how to attach, update, and read custom metadata (customData) on PDF form fields using the Form Designer UI and APIs in the Syncfusion TypeScript PDF Viewer.
5+
platform: document-processing
6+
control: PDF Viewer
7+
documentation: ug
8+
---
9+
10+
# Add custom data to form fields
11+
12+
You can associate arbitrary metadata with any form field using the customData property. This is useful for storing business IDs, validation hints, tags, or any app-specific information alongside the field. The data stays with the field object during the viewer session and can be accessed whenever you query or update fields.
13+
14+
N> customData is a free-form object. You control both its shape and how it is used in your application.
15+
16+
## Add custom data when creating fields (programmatically)
17+
18+
Pass a customData object in the second parameter of addFormField. You can include any serializable values.
19+
20+
```ts
21+
import { PdfViewer, Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView,
22+
TextSelection, Annotation, FormDesigner, FormFields, TextFieldSettings } from '@syncfusion/ej2-pdfviewer';
23+
24+
PdfViewer.Inject(Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, Annotation, FormDesigner, FormFields);
25+
26+
const viewer: PdfViewer = new PdfViewer({
27+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
28+
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib'
29+
});
30+
viewer.appendTo('#pdfViewer');
31+
32+
viewer.documentLoad = () => {
33+
const meta = { businessId: 'C-1024', tags: ['profile', 'kiosk'], requiredRole: 'admin' };
34+
viewer.formDesignerModule.addFormField('Textbox', {
35+
name: 'Email',
36+
bounds: { X: 146, Y: 229, Width: 200, Height: 24 } as TextFieldSettings,
37+
// Attach any custom metadata your app needs
38+
customData: meta
39+
} as any);
40+
};
41+
```
42+
43+
N> To configure the server-backed PDF Viewer, set:
44+
`viewer.serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/';`
45+
46+
## Set default custom data for UI-created fields
47+
48+
When users add fields via the Form Designer toolbar, you can predefine default customData using the per-field settings objects.
49+
50+
```ts
51+
// Example: default custom data for all new Textbox fields added from the toolbar
52+
viewer.textFieldSettings = {
53+
name: 'Textbox',
54+
customData: { group: 'contact', createdBy: 'designer', requiredRole: 'user' }
55+
} as any;
56+
```
57+
58+
You can do the same for other field types using passwordFieldSettings, checkBoxFieldSettings, radioButtonFieldSettings, listBoxFieldSettings, dropDownFieldSettings, signatureFieldSettings, and initialFieldSettings.
59+
60+
## Update or replace custom data on existing fields
61+
62+
Use updateFormField to set or modify the customData of any existing field (retrieved by object or ID).
63+
64+
```ts
65+
const fields = viewer.retrieveFormFields();
66+
const target = fields[0];
67+
viewer.formDesignerModule.updateFormField(target, {
68+
customData: { group: 'profile', flags: ['pii', 'masked'], updatedAt: Date.now() }
69+
} as any);
70+
```
71+
72+
Tip: You can merge new values with existing ones in your app code before calling updateFormField.
73+
74+
## Read custom data
75+
76+
You can read customData from any field at any time. Typical entry points:
77+
- After document load
78+
- On your own UI actions (save, validate, route, etc.)
79+
80+
```ts
81+
viewer.documentLoad = () => {
82+
const fields = viewer.retrieveFormFields();
83+
fields.forEach((f: any) => {
84+
console.log('Field', f.name, 'customData:', f.customData);
85+
});
86+
};
87+
```
88+
89+
## Notes and best practices
90+
91+
- Keep customData small and serializable (plain objects, arrays, numbers, strings, booleans).
92+
- Treat customData as application metadata. Use it to drive business rules, validation, or routing in your app.
93+
- When cloning or copying fields in your UI, also copy or adjust customData as needed.
94+
95+
[View Sample on GitHub](https://github.com/SyncfusionExamples/typescript-pdf-viewer-examples)
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
layout: post
3+
title: Form constraints in the TypeScript PDF Viewer component | Syncfusion
4+
description: Learn how to configure form field constraints such as isReadOnly, isRequired, and isPrint in the Syncfusion TypeScript PDF Viewer.
5+
platform: document-processing
6+
control: PDF Viewer
7+
documentation: ug
8+
---
9+
10+
# Form constraints in TypeScript PDF Viewer
11+
12+
The PDF Viewer components provides support to control user interaction and output behavior of form fields using the following constraints:
13+
14+
- isReadOnly: Prevents users from editing a field.
15+
- isRequired: Marks a field as mandatory and participates in validation.
16+
- isPrint: Includes the field appearance when printing or exporting with print.
17+
18+
You can set these properties when you create fields, update them later programmatically, or configure default settings so fields created from the Form Designer toolbar inherit the values.
19+
20+
## isReadOnly
21+
22+
Use `isReadOnly` to make a field non-editable in the UI while keeping it modifiable via code.
23+
24+
- Creation
25+
```ts
26+
pdfviewer.formDesignerModule.addFormField('Textbox', {
27+
name: 'EmployeeId',
28+
bounds: { X: 146, Y: 229, Width: 150, Height: 24 },
29+
isReadOnly: true,
30+
value: 'EMP-0001'
31+
} as TextFieldSettings);
32+
```
33+
34+
- Update existing field
35+
```ts
36+
const field = pdfviewer.formFieldCollections.find(f => f.name === 'EmployeeId');
37+
if (field) {
38+
pdfviewer.formDesignerModule.updateFormField(field, { isReadOnly: false } as TextFieldSettings);
39+
}
40+
```
41+
42+
- Default for new Textbox fields
43+
```ts
44+
pdfviewer.textFieldSettings = { isReadOnly: true };
45+
```
46+
47+
## isRequired
48+
49+
Use `isRequired` to mark fields as mandatory so they participate in validation during print/download. Turn on validation with enableFormFieldsValidation and handle validateFormFields to block actions if required fields are empty.
50+
51+
- Creation
52+
```ts
53+
pdfviewer.formDesignerModule.addFormField('Textbox', {
54+
name: 'Email',
55+
bounds: { X: 146, Y: 260, Width: 220, Height: 24 },
56+
isRequired: true,
57+
tooltip: 'Email is required'
58+
} as TextFieldSettings);
59+
```
60+
61+
- Validation wiring
62+
```ts
63+
pdfviewer.enableFormFieldsValidation = true;
64+
pdfviewer.validateFormFields = (args: any) => {
65+
//validateFormFields event triggers when fields are empty.
66+
alert("Please fill all required fields. Missing: "+args.formField[0].name);
67+
};
68+
```
69+
70+
- Default for new Textbox fields
71+
```ts
72+
pdfviewer.textFieldSettings = { isRequired: true };
73+
```
74+
75+
## isPrint
76+
77+
Use `isPrint` to control whether a field’s appearance is included when printing the PDF from the viewer.
78+
79+
- Creation (do not print a signature field)
80+
```ts
81+
pdfviewer.formDesignerModule.addFormField('SignatureField', {
82+
name: 'ApplicantSign',
83+
bounds: { X: 57, Y: 923, Width: 200, Height: 43 },
84+
isPrint: false
85+
} as SignatureFieldSettings);
86+
```
87+
88+
- Update existing field
89+
```ts
90+
const sign = pdfviewer.formFieldCollections.find(f => f.name === 'ApplicantSign');
91+
if (sign) {
92+
pdfviewer.formDesignerModule.updateFormField(sign, { isPrint: true } as SignatureFieldSettings);
93+
}
94+
```
95+
96+
- Default for new signature fields
97+
```ts
98+
pdfviewer.signatureFieldSettings = { isPrint: false };
99+
```
100+
101+
N> Printing can be invoked programmatically using pdfviewer.print.print(); fields with isPrint: false will not appear in the print output.
102+
103+
## Set constraints when creating a field
104+
105+
Use `addFormField` to create fields and pass the constraint properties in the settings object. The example below adds a Textbox and a Signature field with different constraint combinations.
106+
107+
```ts
108+
import { PdfViewer, Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView,
109+
TextSelection, Annotation, FormDesigner, FormFields, TextFieldSettings, SignatureFieldSettings } from '@syncfusion/ej2-pdfviewer';
110+
111+
PdfViewer.Inject(Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView,
112+
TextSelection, Annotation, FormDesigner, FormFields);
113+
114+
let pdfviewer: PdfViewer = new PdfViewer({
115+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
116+
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib'
117+
});
118+
pdfviewer.appendTo('#PdfViewer');
119+
120+
pdfviewer.documentLoad = () => {
121+
// Read-only Textbox that is printed but not required
122+
pdfviewer.formDesignerModule.addFormField('Textbox', {
123+
name: 'EmployeeId',
124+
bounds: { X: 146, Y: 229, Width: 150, Height: 24 },
125+
isReadOnly: true,
126+
isRequired: false,
127+
isPrint: true,
128+
value: 'EMP-0001'
129+
} as TextFieldSettings);
130+
131+
// Required Signature field that is not included in print
132+
pdfviewer.formDesignerModule.addFormField('SignatureField', {
133+
name: 'ApplicantSign',
134+
bounds: { X: 57, Y: 923, Width: 200, Height: 43 },
135+
isReadOnly: false,
136+
isRequired: true,
137+
isPrint: false,
138+
tooltip: 'Sign to accept the terms'
139+
} as SignatureFieldSettings);
140+
};
141+
```
142+
143+
N> To configure the server-backed PDF Viewer, add the following serviceUrl in index.ts:
144+
`pdfviewer.serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/';`
145+
146+
## Update constraints programmatically
147+
148+
Use `updateFormField` to change constraint flags of an existing field. The snippet below toggles isReadOnly, sets a field as required, and controls whether the field should appear when printing.
149+
150+
```ts
151+
import { PdfViewer, Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView,
152+
TextSelection, Annotation, FormDesigner, FormFields, TextFieldSettings } from '@syncfusion/ej2-pdfviewer';
153+
154+
PdfViewer.Inject(Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView,
155+
TextSelection, Annotation, FormDesigner, FormFields);
156+
157+
let pdfviewer: PdfViewer = new PdfViewer({
158+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
159+
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib'
160+
});
161+
pdfviewer.appendTo('#PdfViewer');
162+
163+
pdfviewer.documentLoad = () => {
164+
// Add a sample textbox
165+
pdfviewer.formDesignerModule.addFormField('Textbox', {
166+
name: 'Email',
167+
bounds: { X: 146, Y: 260, Width: 220, Height: 24 }
168+
} as TextFieldSettings);
169+
170+
// Retrieve it and update constraint flags
171+
const field = pdfviewer.formFieldCollections.find(f => f.name === 'Email');
172+
if (field) {
173+
pdfviewer.formDesignerModule.updateFormField(field, {
174+
isReadOnly: false,
175+
isRequired: true,
176+
isPrint: true,
177+
tooltip: 'Enter a valid email'
178+
} as TextFieldSettings);
179+
}
180+
};
181+
```
182+
183+
## Configure default constraints for newly added fields
184+
185+
Set default settings so all fields created from the Form Designer toolbar inherit the constraint flags.
186+
187+
The example below configures defaults for Textbox and Signature fields.
188+
189+
```ts
190+
import { PdfViewer, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView,
191+
BookmarkView, TextSelection, FormDesigner, FormFields } from '@syncfusion/ej2-pdfviewer';
192+
193+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView,
194+
BookmarkView, TextSelection, FormDesigner, FormFields);
195+
196+
let pdfviewer: PdfViewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
197+
pdfviewer.appendTo('#PdfViewer');
198+
199+
// Textbox fields will be editable, required, and included in print by default
200+
pdfviewer.textFieldSettings = {
201+
isReadOnly: false,
202+
isRequired: true,
203+
isPrint: true,
204+
tooltip: 'Required field'
205+
};
206+
207+
// Signature fields will be optional and hidden when printing
208+
pdfviewer.signatureFieldSettings = {
209+
isReadOnly: false,
210+
isRequired: false,
211+
isPrint: false,
212+
tooltip: 'Sign if applicable'
213+
};
214+
```
215+
216+
## Behavior notes
217+
218+
- isReadOnly only blocks user edits in the UI. You can still update the field programmatically.
219+
- isRequired participates in the built-in validation flow. Enable validation to enforce before print/download. See Validate form fields for details.
220+
- isPrint controls field appearance in the print output. It does not affect download/export unless printing is triggered.
221+
222+
[View Sample on GitHub](https://github.com/SyncfusionExamples/typescript-pdf-viewer-examples)
223+

0 commit comments

Comments
 (0)