Skip to content

Commit 08b83fa

Browse files
983156: Updated Comments in app.component.ts
1 parent 07cb459 commit 08b83fa

File tree

1 file changed

+71
-70
lines changed
  • How to/Dynamically show or hide the Download and Open toolbar items using checkboxes/src/app

1 file changed

+71
-70
lines changed
Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,83 @@
1-
import { Component, ViewEncapsulation, OnInit,ViewChild} from '@angular/core';
2-
import { PdfViewerComponent, LinkAnnotationService, BookmarkViewService, MagnificationService, ThumbnailViewService, ToolbarService, NavigationService, TextSearchService, TextSelectionService, PrintService, AnnotationService, FormFieldsService, FormDesignerService, PageOrganizerService,PdfViewerModule, TextSelectionStartEventArgs, AnnotationSelectEventArgs } from '@syncfusion/ej2-angular-pdfviewer';
1+
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
2+
import {
3+
PdfViewerComponent, PdfViewerModule, ToolbarService,
4+
LinkAnnotationService, BookmarkViewService, MagnificationService,
5+
ThumbnailViewService, NavigationService, TextSearchService,
6+
TextSelectionService, PrintService, AnnotationService,
7+
FormFieldsService, FormDesignerService, PageOrganizerService
8+
} from '@syncfusion/ej2-angular-pdfviewer';
39
import { SwitchComponent, SwitchModule } from '@syncfusion/ej2-angular-buttons';
4-
import { ClickEventArgs } from '@syncfusion/ej2-buttons';
510
import { FormsModule } from '@angular/forms';
611

7-
8-
9-
/**
10-
* Default PdfViewer Controller
11-
*/
1212
@Component({
13-
selector: 'app-root',
14-
templateUrl: 'app.component.html',
15-
encapsulation: ViewEncapsulation.None,
16-
// tslint:disable-next-line:max-line-length
17-
providers: [LinkAnnotationService, BookmarkViewService, MagnificationService, ThumbnailViewService, ToolbarService, NavigationService,
18-
TextSearchService, TextSelectionService, PrintService, AnnotationService, FormFieldsService, FormDesignerService,PageOrganizerService],
19-
styleUrls: ['app.component.css'],
20-
standalone: true,
21-
imports: [
22-
FormsModule,
23-
SwitchModule,
24-
PdfViewerModule,
25-
26-
],
13+
selector: 'app-root',
14+
templateUrl: 'app.component.html',
15+
encapsulation: ViewEncapsulation.None,
16+
providers: [
17+
// Injecting required services for PDF Viewer functionality
18+
LinkAnnotationService, BookmarkViewService, MagnificationService,
19+
ThumbnailViewService, ToolbarService, NavigationService,
20+
TextSearchService, TextSelectionService, PrintService,
21+
AnnotationService, FormFieldsService, FormDesignerService, PageOrganizerService
22+
],
23+
styleUrls: ['app.component.css'],
24+
standalone: true,
25+
imports: [FormsModule, SwitchModule, PdfViewerModule],
2726
})
28-
2927
export class AppComponent {
30-
@ViewChild('pdfviewer')
31-
public pdfviewerControl: PdfViewerComponent | undefined;
32-
@ViewChild('switch')
33-
public switch: SwitchComponent | undefined;
34-
35-
public document: string = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
36-
public resource:string = "https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib";
37-
public toolbarItems: string[] = [
38-
'OpenOption', 'PageNavigationTool', 'MagnificationTool', 'PanTool',
39-
'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption',
40-
'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool',
41-
'CommentTool', 'SubmitForm'
42-
];
43-
public toolbarSettings = { showTooltip: true, toolbarItems: [...this.toolbarItems] };
44-
45-
public downloadEnabled = true;
46-
public openEnabled = true;
28+
// Reference to the PDF Viewer component
29+
@ViewChild('pdfviewer') public pdfviewerControl: PdfViewerComponent | undefined;
4730

48-
ngOnInit(): void {
49-
// ngOnInit function
50-
}
51-
public onCheckbox1Change(event: any): void {
52-
this.toggleToolbarItem('DownloadOption', event.target.checked);
53-
}
31+
// PDF document path and resource URL
32+
public document: string = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
33+
public resource: string = 'https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib';
5434

55-
public onCheckbox2Change(event: any): void {
56-
this.toggleToolbarItem('OpenOption', event.target.checked);
57-
}
35+
// Initial toolbar items to be displayed
36+
public toolbarItems: string[] = [
37+
'OpenOption', 'PageNavigationTool', 'MagnificationTool', 'PanTool',
38+
'SelectionTool', 'SearchOption', 'PrintOption', 'DownloadOption',
39+
'UndoRedoTool', 'AnnotationEditTool', 'FormDesignerEditTool',
40+
'CommentTool', 'SubmitForm'
41+
];
42+
43+
// Toolbar settings configuration
44+
public toolbarSettings = { showTooltip: true, toolbarItems: [...this.toolbarItems] };
5845

59-
private toggleToolbarItem(item: string, show: boolean): void {
60-
const index = this.toolbarItems.indexOf(item);
61-
62-
if (show && index === -1) {
63-
this.toolbarItems.push(item);
64-
} else if (!show && index !== -1) {
65-
this.toolbarItems.splice(index, 1);
66-
}
67-
68-
// Update toolbarSettings
69-
this.toolbarSettings = {
70-
showTooltip: true,
71-
toolbarItems: [...this.toolbarItems]
72-
};
73-
74-
// Apply new settings and reload the viewer
75-
this.toolbarSettings = this.toolbarSettings;
76-
this.pdfviewerControl?.dataBind();
77-
this.pdfviewerControl?.load(this.document, ""); // ✅ This forces toolbar to re-render
46+
// Checkbox model bindings
47+
public downloadEnabled = true;
48+
public openEnabled = true;
49+
50+
// Handler for 'Download' checkbox change
51+
public onCheckbox1Change(event: any): void {
52+
this.toggleToolbarItem('DownloadOption', event.target.checked);
53+
}
54+
55+
// Handler for 'Open' checkbox change
56+
public onCheckbox2Change(event: any): void {
57+
this.toggleToolbarItem('OpenOption', event.target.checked);
58+
}
59+
60+
// Method to toggle toolbar items based on checkbox state
61+
private toggleToolbarItem(item: string, show: boolean): void {
62+
const index = this.toolbarItems.indexOf(item);
63+
64+
// Add item if not present and checkbox is checked
65+
if (show && index === -1) {
66+
this.toolbarItems.push(item);
67+
}
68+
// Remove item if present and checkbox is unchecked
69+
else if (!show && index !== -1) {
70+
this.toolbarItems.splice(index, 1);
7871
}
79-
8072

81-
}
73+
// Update toolbar settings and rebind PDF Viewer
74+
this.toolbarSettings = {
75+
showTooltip: true,
76+
toolbarItems: [...this.toolbarItems]
77+
};
8278

79+
// Refresh the PDF Viewer with updated toolbar
80+
this.pdfviewerControl?.dataBind();
81+
this.pdfviewerControl?.load(this.document, '');
82+
}
83+
}

0 commit comments

Comments
 (0)