Skip to content

Commit 1ec05fd

Browse files
1001080: Forms Sample JS
1 parent 79961b3 commit 1ec05fd

File tree

12 files changed

+1002
-0
lines changed

12 files changed

+1002
-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: 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)