1WebViewer(...)
2.then(instance => {
3 const { annotationManager, Annotations } = instance.Core;
4 const { WidgetFlags } = Annotations;
5
6 // myBtn is your own custom button
7 document.getElementById('myBtn').addEventListener('click', () => {
8
9 // set flags for required
10 const flags = new WidgetFlags();
11 flags.set('Required', true);
12
13 // create a form field
14 const field = new Annotations.Forms.Field("some signature field name", {
15 type: 'Sig',
16 flags,
17 });
18
19 // create a widget annotation
20 const widgetAnnot = new Annotations.SignatureWidgetAnnotation(field, {
21 appearance: '_DEFAULT',
22 appearances: {
23 _DEFAULT: {
24 Normal: {
25 offset: {
26 x: 100,
27 y: 100,
28 },
29 },
30 },
31 },
32 // If this option is passed, the widget will apply any
33 // initials created by the user in the Signature Modal
34 requiresInitials: true,
35 });
36
37 // set position and size
38 widgetAnnot.PageNumber = 1;
39 widgetAnnot.X = 100;
40 widgetAnnot.Y = 100;
41 widgetAnnot.Width = 50;
42 widgetAnnot.Height = 20;
43
44 //add the form field and widget annotation
45 annotationManager.getFieldManager().addField(field);
46 annotationManager.addAnnotation(widgetAnnot);
47 annotationManager.drawAnnotationsFromList([widgetAnnot]);
48 });
49});
50
51[Create fillable PDF forms](/web/samples/forms/#form-builder-demo)<br>
52Full sample code demonstrating how to add form fields to a PDF. Fields are first added as annotations and then converted to interactive form fields. Add signatures, text fields, checkboxes.
53
54@CHUNK web/widget-flags