Skip to content

Commit 5ce339d

Browse files
Merge pull request #48 from SyncfusionExamples/1001080-formsSample
1001080 forms sample
2 parents 79961b3 + 7a03880 commit 5ce339d

File tree

20 files changed

+1440
-0
lines changed

20 files changed

+1440
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<title>EJ2 PDF Viewer</title>
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="description" content="Typescript PDF Viewer Control">
6+
<meta name="author" content="Syncfusion">
7+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css" rel="stylesheet">
8+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-pdfviewer/styles/material.css" rel="stylesheet">
9+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
10+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-dropdowns/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-notifications/styles/material.css" rel="stylesheet">
17+
18+
<!-- Essential JS 2 PDF Viewer's script -->
19+
<script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js" type="text/javascript"></script>
20+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
21+
22+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
23+
</head>
24+
<body>
25+
<div id="container">
26+
<button id="formFieldCollection">Fetch Form Fields Collection</button>
27+
<div id="PdfViewer" style="height:500px;width:100%;"></div>
28+
</div>
29+
30+
31+
<script>
32+
var ele = document.getElementById('container');
33+
if(ele) {
34+
ele.style.visibility = "visible";
35+
}
36+
</script>
37+
<script src="index.js" type="text/javascript"></script>
38+
</body></html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var pdfviewer = new ej.pdfviewer.PdfViewer({
2+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf',
3+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib",
4+
enableFormDesigner: true, //Set 'false' to disable form designer
5+
});
6+
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.Toolbar,
7+
ej.pdfviewer.Magnification, ej.pdfviewer.Annotation, ej.pdfviewer.FormDesigner, ej.pdfviewer.FormFields, ej.pdfviewer.PageOrganizer);
8+
pdfviewer.appendTo('#PdfViewer');
9+
10+
//Click event to get formfields collection
11+
document.getElementById('formFieldCollection').addEventListener('click', function() {
12+
var fields = pdfviewer.formFieldCollection; // Gets all form fields
13+
console.log(fields); // Log the formField Collection
14+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<title>EJ2 PDF Viewer</title>
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="description" content="Typescript PDF Viewer Control">
6+
<meta name="author" content="Syncfusion">
7+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css" rel="stylesheet">
8+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-pdfviewer/styles/material.css" rel="stylesheet">
9+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
10+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-dropdowns/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-notifications/styles/material.css" rel="stylesheet">
17+
18+
<!-- Essential JS 2 PDF Viewer's script -->
19+
<script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js" type="text/javascript"></script>
20+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
21+
22+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
23+
</head>
24+
<body>
25+
<div id="container">
26+
<div class="toolbar">
27+
<button id="btnAddTextbox">Add Textbox</button>
28+
<button id="btnAddPassword">Add Password</button>
29+
<button id="btnAddCheckbox">Add CheckBox</button>
30+
<button id="btnAddRadioGroup">Add Radio Group (Gender)</button>
31+
<button id="btnAddListBox">Add ListBox</button>
32+
<button id="btnAddDropDown">Add DropDown</button>
33+
<button id="btnAddSignature">Add Signature</button>
34+
<button id="btnAddInitial">Add Initial</button>
35+
<button id="btnDrawPassword">Draw Next As Password (setFormFieldMode)</button>
36+
</div>
37+
38+
<div id="PdfViewer" style="height:500px;width:100%;"></div>
39+
</div>
40+
41+
42+
<script>
43+
var ele = document.getElementById('container');
44+
if(ele) {
45+
ele.style.visibility = "visible";
46+
}
47+
</script>
48+
<script src="index.js" type="text/javascript"></script>
49+
</body></html>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
(function () {
2+
// Initialize the PDF Viewer
3+
var pdfviewer = new ej.pdfviewer.PdfViewer({
4+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf',
5+
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib'
6+
});
7+
8+
ej.pdfviewer.PdfViewer.Inject(
9+
ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.Navigation, ej.pdfviewer.Annotation,
10+
ej.pdfviewer.LinkAnnotation, ej.pdfviewer.ThumbnailView, ej.pdfviewer.BookmarkView,
11+
ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.FormFields, ej.pdfviewer.FormDesigner
12+
);
13+
14+
pdfviewer.appendTo('#PdfViewer');
15+
16+
// Optional: add an initial example after document load (can be removed)
17+
pdfviewer.documentLoad = function () {
18+
// Example: place a default textbox when loaded
19+
try {
20+
pdfviewer.formDesignerModule.addFormField('Textbox', {
21+
name: 'First Name',
22+
bounds: { X: 146, Y: 229, Width: 150, Height: 24 }
23+
});
24+
} catch (e) { console.warn(e); }
25+
};
26+
27+
// Button handlers
28+
function addTextbox() {
29+
pdfviewer.formDesignerModule.addFormField('Textbox', {
30+
name: 'First Name',
31+
bounds: { X: 146, Y: 229, Width: 150, Height: 24 }
32+
});
33+
}
34+
35+
function addPassword() {
36+
pdfviewer.formDesignerModule.addFormField('Password', {
37+
name: 'Account Password',
38+
bounds: { X: 148, Y: 270, Width: 180, Height: 24 }
39+
});
40+
}
41+
42+
function addCheckbox() {
43+
pdfviewer.formDesignerModule.addFormField('CheckBox', {
44+
name: 'Subscribe',
45+
isChecked: false,
46+
bounds: { X: 56, Y: 664, Width: 20, Height: 20 }
47+
});
48+
}
49+
50+
function addRadioGroup() {
51+
// Group by same name: 'Gender'
52+
pdfviewer.formDesignerModule.addFormField('RadioButton', {
53+
name: 'Gender',
54+
isSelected: false,
55+
bounds: { X: 148, Y: 289, Width: 18, Height: 18 }
56+
});
57+
pdfviewer.formDesignerModule.addFormField('RadioButton', {
58+
name: 'Gender',
59+
isSelected: false,
60+
bounds: { X: 292, Y: 289, Width: 18, Height: 18 }
61+
});
62+
}
63+
64+
function addListBox() {
65+
var options = [
66+
{ itemName: 'Item 1', itemValue: 'item1' },
67+
{ itemName: 'Item 2', itemValue: 'item2' },
68+
{ itemName: 'Item 3', itemValue: 'item3' }
69+
];
70+
pdfviewer.formDesignerModule.addFormField('ListBox', {
71+
name: 'States',
72+
options: options,
73+
bounds: { X: 380, Y: 320, Width: 150, Height: 60 }
74+
});
75+
}
76+
77+
function addDropDown() {
78+
var options = [
79+
{ itemName: 'Item 1', itemValue: 'item1' },
80+
{ itemName: 'Item 2', itemValue: 'item2' },
81+
{ itemName: 'Item 3', itemValue: 'item3' }
82+
];
83+
pdfviewer.formDesignerModule.addFormField('DropDown', {
84+
name: 'Country',
85+
options: options,
86+
bounds: { X: 560, Y: 320, Width: 150, Height: 24 }
87+
});
88+
}
89+
90+
function addSignature() {
91+
pdfviewer.formDesignerModule.addFormField('SignatureField', {
92+
name: 'Sign',
93+
bounds: { X: 57, Y: 923, Width: 200, Height: 43 }
94+
});
95+
}
96+
97+
function addInitial() {
98+
pdfviewer.formDesignerModule.addFormField('InitialField', {
99+
name: 'Initial',
100+
bounds: { X: 148, Y: 466, Width: 200, Height: 43 }
101+
});
102+
}
103+
104+
function drawNextAsPassword() {
105+
// Switch to interactive draw mode; click on the PDF to place the field
106+
pdfviewer.formDesignerModule.setFormFieldMode('Password');
107+
}
108+
109+
// Wire up buttons
110+
document.getElementById('btnAddTextbox').addEventListener('click', addTextbox);
111+
document.getElementById('btnAddPassword').addEventListener('click', addPassword);
112+
document.getElementById('btnAddCheckbox').addEventListener('click', addCheckbox);
113+
document.getElementById('btnAddRadioGroup').addEventListener('click', addRadioGroup);
114+
document.getElementById('btnAddListBox').addEventListener('click', addListBox);
115+
document.getElementById('btnAddDropDown').addEventListener('click', addDropDown);
116+
document.getElementById('btnAddSignature').addEventListener('click', addSignature);
117+
document.getElementById('btnAddInitial').addEventListener('click', addInitial);
118+
document.getElementById('btnDrawPassword').addEventListener('click', drawNextAsPassword);
119+
})();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<title>EJ2 PDF Viewer</title>
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="description" content="Typescript PDF Viewer Control">
6+
<meta name="author" content="Syncfusion">
7+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css" rel="stylesheet">
8+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-pdfviewer/styles/material.css" rel="stylesheet">
9+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
10+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-dropdowns/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-notifications/styles/material.css" rel="stylesheet">
17+
18+
<!-- Essential JS 2 PDF Viewer's script -->
19+
<script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js" type="text/javascript"></script>
20+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
21+
22+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
23+
</head>
24+
<body>
25+
<button id="updateCustomData">Update first field customData</button>
26+
<button id="logCustomData">Log all fields customData</button>
27+
<div id="pdfViewer" style="height:500px;width:100%;"></div>
28+
</div>
29+
30+
31+
<script>
32+
var ele = document.getElementById('container');
33+
if(ele) {
34+
ele.style.visibility = "visible";
35+
}
36+
</script>
37+
<script src="index.js" type="text/javascript"></script>
38+
</body></html>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Inject required modules (ES5)
2+
ej.pdfviewer.PdfViewer.Inject(
3+
ej.pdfviewer.Toolbar,
4+
ej.pdfviewer.Magnification,
5+
ej.pdfviewer.Navigation,
6+
ej.pdfviewer.LinkAnnotation,
7+
ej.pdfviewer.ThumbnailView,
8+
ej.pdfviewer.BookmarkView,
9+
ej.pdfviewer.TextSelection,
10+
ej.pdfviewer.Annotation,
11+
ej.pdfviewer.FormDesigner,
12+
ej.pdfviewer.FormFields
13+
);
14+
15+
var viewer = new ej.pdfviewer.PdfViewer({
16+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
17+
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib'
18+
// For server-backed:
19+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/'
20+
});
21+
viewer.appendTo('#pdfViewer');
22+
23+
// Default customData for fields added via Form Designer toolbar
24+
viewer.textFieldSettings = {
25+
name: 'Textbox',
26+
customData: { group: 'contact', createdBy: 'designer', requiredRole: 'user' }
27+
};
28+
29+
// Add a field programmatically with customData after document loads
30+
viewer.documentLoad = function () {
31+
var meta = { businessId: 'C-1024', tags: ['profile', 'kiosk'], requiredRole: 'admin' };
32+
viewer.formDesignerModule.addFormField('Textbox', {
33+
name: 'Email',
34+
bounds: { X: 146, Y: 229, Width: 200, Height: 24 },
35+
customData: meta
36+
});
37+
};
38+
39+
// Helper to get first field
40+
function getFirstField() {
41+
var fields = (viewer.retrieveFormFields && viewer.retrieveFormFields()) || viewer.formFieldCollections || [];
42+
return fields && fields.length ? fields[0] : null;
43+
}
44+
45+
// Update/replace customData on an existing field
46+
var btnUpdate = document.getElementById('updateCustomData');
47+
if (btnUpdate) {
48+
btnUpdate.addEventListener('click', function () {
49+
var target = getFirstField();
50+
if (!target) { alert('No form fields found'); return; }
51+
viewer.formDesignerModule.updateFormField(target, {
52+
customData: { group: 'profile', flags: ['pii', 'masked'], updatedAt: Date.now() }
53+
});
54+
alert('customData updated on first field');
55+
});
56+
}
57+
58+
// Read customData from all fields
59+
var btnLog = document.getElementById('logCustomData');
60+
if (btnLog) {
61+
btnLog.addEventListener('click', function () {
62+
var fields = (viewer.retrieveFormFields && viewer.retrieveFormFields()) || viewer.formFieldCollections || [];
63+
if (!fields.length) { console.log('No fields'); return; }
64+
fields.forEach(function (f, i) {
65+
console.log('#' + i + ' ' + f.name, f.customData);
66+
});
67+
alert('Check console for customData logs');
68+
});
69+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<title>EJ2 PDF Viewer</title>
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="description" content="Typescript PDF Viewer Control">
6+
<meta name="author" content="Syncfusion">
7+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css" rel="stylesheet">
8+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-pdfviewer/styles/material.css" rel="stylesheet">
9+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
10+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-dropdowns/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-notifications/styles/material.css" rel="stylesheet">
17+
18+
<!-- Essential JS 2 PDF Viewer's script -->
19+
<script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js" type="text/javascript"></script>
20+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
21+
22+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
23+
</head>
24+
<body>
25+
<div id="container">
26+
<div class="toolbar">
27+
<button id="editTextbox">Apply Textbox Changes</button>
28+
<button id="editPasswordBox">Edit PasswordBox</button>
29+
<button id="editCheckbox">Edit CheckBox</button>
30+
<button id="editRadio">Edit RadioButton</button>
31+
<button id="editListBox">Edit ListBox</button>
32+
<button id="editDropDown">Edit DropDown</button>
33+
<button id="editSignature">Edit Signature</button>
34+
<button id="editInitial">Edit Initial</button>
35+
</div>
36+
<div id="PdfViewer" style="height:500px;width:100%;"></div>
37+
</div>
38+
39+
40+
<script>
41+
var ele = document.getElementById('container');
42+
if(ele) {
43+
ele.style.visibility = "visible";
44+
}
45+
</script>
46+
<script src="index.js" type="text/javascript"></script>
47+
</body></html>

0 commit comments

Comments
 (0)