Skip to content

Commit 797810b

Browse files
committed
(feat): trigger added
1 parent 357a20c commit 797810b

File tree

8 files changed

+341
-61
lines changed

8 files changed

+341
-61
lines changed

SyncPDFViewerInterop.Sample/Components/Pages/Home.razor

+40-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ Welcome to your new app.
2020
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleTextBoxFieldClick">
2121
Add Text Box Field
2222
</MudButton>
23+
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleCheckBoxFieldClick">
24+
Add CheckBox Field
25+
</MudButton>
26+
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleAddRadioBoxFieldClick">
27+
Add RadioBox Field
28+
</MudButton>
29+
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleAddDropdownFieldClick">
30+
Add Dropdown Field
31+
</MudButton>
32+
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleAddListBoxFieldClick">
33+
Add Listbox Field
34+
</MudButton>
35+
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleUpdateFieldClick">
36+
Update Field
37+
</MudButton>
2338
<MudCheckBox T="bool" Value="checkBoxValue" Label="@DisplayNme" ValueChanged="HandleCheckBoxChanged" />
2439
<PDFViewer >
2540

@@ -44,7 +59,7 @@ Welcome to your new app.
4459
//await pdfViewer.LoadPDF("https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf");
4560
string url = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
4661
var pdfStream = await ConvertUrlToMemoryStreamAsync(url);
47-
await pdfViewer.LoadPDF(pdfStream, "application/pdf");
62+
await pdfViewer.LoadPDF(pdfStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
4863
StateHasChanged();
4964
}
5065
private async Task<byte[]> ConvertUrlToMemoryStreamAsync(string url)
@@ -86,4 +101,28 @@ Welcome to your new app.
86101
await pdfViewer.AddTextBoxField();
87102
StateHasChanged();
88103
}
104+
protected async Task HandleUpdateFieldClick()
105+
{
106+
StateHasChanged();
107+
}
108+
protected async Task HandleCheckBoxFieldClick()
109+
{
110+
await pdfViewer.AddCheckBoxField();
111+
StateHasChanged();
112+
}
113+
protected async Task HandleAddRadioBoxFieldClick()
114+
{
115+
await pdfViewer.AddRadioBoxField();
116+
StateHasChanged();
117+
}
118+
protected async Task HandleAddListBoxFieldClick()
119+
{
120+
await pdfViewer.AddListBoxField();
121+
StateHasChanged();
122+
}
123+
protected async Task HandleAddDropdownFieldClick()
124+
{
125+
await pdfViewer.AddDropdownField();
126+
StateHasChanged();
127+
}
89128
}

SyncPDFViewerInterop/Interfaces/IPDFViewerInterop.cs

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace SyncPDFViewerInterop.Interfaces
1+
using SyncPDFViewerInterop.Models;
2+
3+
namespace SyncPDFViewerInterop.Interfaces
24
{
35
public interface IPDFViewerInterop
46
{
@@ -34,17 +36,48 @@ public interface IPDFViewerInterop
3436
/// </summary>
3537
/// <returns></returns>
3638
Task AddTextBoxField();
39+
/// <summary>
40+
/// Add Checkbox Field for the PDF Viewer
41+
/// </summary>
42+
/// <returns></returns>
43+
Task AddCheckBoxField();
3744
/// <summary>
38-
/// Add Initial Field for the pdf Viewer
45+
/// Add Radiobox Field for the PDF Viewer
3946
/// </summary>
4047
/// <returns></returns>
48+
Task AddRadioBoxField();
49+
/// <summary>
50+
/// Add Dropdown Field for the PDF Viewer
51+
/// </summary>
52+
/// <returns></returns>
53+
Task AddDropdownField();
54+
/// <summary>
55+
/// Add Initial Field for the PDF Viewer
56+
/// </summary>
57+
/// <returns></returns>
58+
4159
Task AddInitialField();
4260
/// <summary>
61+
/// Add ListBox Field for th PDF Viewer
62+
/// </summary>
63+
/// <returns></returns>
64+
Task AddListBoxField();
65+
/// <summary>
4366
/// Change the PDF viewer From Designer to Reader Mode or vise versa
4467
/// </summary>
4568
/// <param name="isEditMode"></param>
4669
/// <returns></returns>
4770
Task SetFormFieldMode(bool isEditMode);
71+
/// <summary>
72+
/// Update Field
73+
/// </summary>
74+
/// <returns></returns>
75+
Task UpdateField(string id, string name, bool isReadOnly, bool visibility, bool isRequired, bool isPrint, string tooltip);
76+
77+
/// <summary>
78+
/// Triggers when form field is added
79+
/// </summary>
80+
event EventHandler<FormFieldArgs>? FormFieldAdded;
4881
ValueTask DisposeAsync();
4982
}
5083
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace SyncPDFViewerInterop.Models
2+
{
3+
4+
public class FormFieldArgs
5+
{
6+
public string? name { get; set; }
7+
public Field? field { get; set; }
8+
public int pageIndex { get; set; }
9+
}
10+
11+
public class Field
12+
{
13+
public string? name { get; set; }
14+
public string? id { get; set; }
15+
public string? value { get; set; }
16+
public string? fontFamily { get; set; }
17+
public int? fontSize { get; set; }
18+
public string? fontStyle { get; set; }
19+
public string? color { get; set; }
20+
public string? backgroundColor { get; set; }
21+
public string? alignment { get; set; }
22+
public bool isReadonly { get; set; }
23+
public string? visibility { get; set; }
24+
public int? maxLength { get; set; }
25+
public bool isRequired { get; set; }
26+
public bool isPrint { get; set; }
27+
public int? rotation { get; set; }
28+
public string? tooltip { get; set; }
29+
public string? borderColor { get; set; }
30+
public int thickness { get; set; }
31+
public string? options { get; set; }
32+
public int? pageNumber { get; set; }
33+
public bool isChecked { get; set; }
34+
public bool isSelected { get; set; }
35+
}
36+
37+
}

SyncPDFViewerInterop/Npm/src/js/pdfViewerInterop.js

+82-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ export async function configure(dotNetInterop) {
3131
try {
3232
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView,
3333
BookmarkView, TextSelection, TextSearch, FormFields, FormDesigner, PageOrganizer);
34-
35-
pdfviewer = new PdfViewer();
34+
pdfviewer = new PdfViewer({
35+
formFieldAdd: function (args) {
36+
dotNetInterop.invokeMethodAsync('OnFormFieldAdded', args);
37+
}
38+
});
3639
configured = true;
3740
} catch (e) {
3841
console.log(e.message);
@@ -73,10 +76,10 @@ export async function addSignatureField() {
7376
try {
7477
if (pdfviewer != null) {
7578
const signatureFormElement = document.getElementById('pdfViewer_formfield_signature');
76-
const signatureDialog = document.getElementById('pdfViewer_formfield_signature-popup');
79+
7780
if (signatureFormElement != null) {
7881
signatureFormElement.click();
79-
82+
const signatureDialog = document.getElementById('pdfViewer_formfield_signature-popup');
8083
if (signatureDialog != null) {
8184
const signatureDrawButton = signatureDialog.firstElementChild.firstElementChild.firstElementChild;
8285
if (signatureDrawButton != null) {
@@ -94,10 +97,10 @@ export async function addInitialField() {
9497
try {
9598
if (pdfviewer != null) {
9699
const initialFormElement = document.getElementById('pdfViewer_formfield_signature');
97-
const initialDialog = document.getElementById('pdfViewer_formfield_signature-popup');
100+
98101
if (initialFormElement != null) {
99102
initialFormElement.click();
100-
103+
const initialDialog = document.getElementById('pdfViewer_formfield_signature-popup');
101104
if (initialDialog != null) {
102105
const initialDrawButton = initialDialog.lastElementChild.lastElementChild.firstElementChild;
103106
if (initialDrawButton != null) {
@@ -124,17 +127,69 @@ export async function addTextBoxField() {
124127
console.error(e.message);
125128
}
126129
}
130+
export async function addCheckBoxField() {
131+
try {
132+
if (pdfviewer != null) {
133+
const checkbox = document.getElementById('pdfViewer_formdesigner_checkbox');
134+
if (checkbox != null) {
135+
checkbox.click();
136+
}
137+
}
138+
139+
} catch (e) {
140+
console.error(e.message);
141+
}
142+
}
143+
export async function addRadioBoxField() {
144+
try {
145+
if (pdfviewer != null) {
146+
const radiobox = document.getElementById('pdfViewer_formdesigner_radiobutton');
147+
if (radiobox != null) {
148+
radiobox.click();
149+
}
150+
}
151+
152+
} catch (e) {
153+
console.error(e.message);
154+
}
155+
}
156+
export async function addDropdownField() {
157+
try {
158+
if (pdfviewer != null) {
159+
const dropdown = document.getElementById('pdfViewer_formdesigner_dropdown');
160+
if (dropdown != null) {
161+
dropdown.click();
162+
}
163+
}
164+
165+
} catch (e) {
166+
console.error(e.message);
167+
}
168+
}
169+
export async function addListboxField() {
170+
try {
171+
if (pdfviewer != null) {
172+
const listbox = document.getElementById('pdfViewer_formdesigner_listbox');
173+
if (listbox != null) {
174+
listbox.click();
175+
}
176+
}
177+
178+
} catch (e) {
179+
console.error(e.message);
180+
}
181+
}
127182
export async function setFormFieldMode(mode) {
128183
try {
129184
if (pdfviewer != null) {
130185
const addEditFormFieldButton = document.getElementById('pdfViewer_formdesigner');
131186
if (addEditFormFieldButton != null) {
132-
if (mode) {
187+
if (isDesignerMode == false && mode == true) {
133188
pdfviewer.enableFormDesigner = true;
134189
isDesignerMode = true;
135190
addEditFormFieldButton.click();
136191
}
137-
else {
192+
else if (isDesignerMode == true && mode == false) {
138193
addEditFormFieldButton.click();
139194
isDesignerMode = false;
140195
}
@@ -145,6 +200,25 @@ export async function setFormFieldMode(mode) {
145200

146201
}
147202
}
203+
export async function updateField(id, _name, _isReadOnly, _visibility, _isRequired, _isPrint, _tooltip) {
204+
try {
205+
if (pdfviewer != null) {
206+
var formField = pdfviewer.getFormFieldByID(id);
207+
pdfviewer.formDesignerModule.updateFormField(formField, {
208+
name: _name,
209+
isReadOnly: _isReadOnly,
210+
visibility: _visibility,
211+
isRequired: _isRequired,
212+
isPrint: _isPrint,
213+
tooltip: _tooltip,
214+
thickness: 1
215+
});
216+
}
217+
} catch (e) {
218+
219+
}
220+
221+
}
148222
document.addEventListener('DOMContentLoaded', (event) => {
149223
configure().then(() => {
150224
loadPDF('https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf');

0 commit comments

Comments
 (0)