1
+ import { Component , OnInit , ViewChild } from '@angular/core' ;
2
+ import {
3
+ LinkAnnotationService ,
4
+ BookmarkViewService ,
5
+ MagnificationService ,
6
+ ThumbnailViewService ,
7
+ ToolbarService ,
8
+ NavigationService ,
9
+ AnnotationService ,
10
+ TextSearchService ,
11
+ TextSelectionService ,
12
+ FormFieldsService ,
13
+ FormDesignerService ,
14
+ PrintService
15
+ } from '@syncfusion/ej2-angular-pdfviewer' ;
16
+
17
+ @Component ( {
18
+ selector : 'app-root' ,
19
+ template : `
20
+ <div class="content-wrapper">
21
+ <div style="margin-top: 20px;">
22
+ <button (click)="handleSearch()">Search PDF</button>
23
+ <button (click)="handleSearchNext()">Search Next</button>
24
+ <button (click)="handleCancelSearch()">Cancel Search</button>
25
+ </div>
26
+ <ejs-pdfviewer #pdfViewer
27
+ id="pdfViewer"
28
+ [documentPath]='document'
29
+ [resourceUrl]='resource'
30
+ style="height:640px;display:block"
31
+ (textSearchHighlight)="handleTextSearchHighlight($event)">
32
+ </ejs-pdfviewer>
33
+ </div>
34
+ ` ,
35
+ providers : [
36
+ LinkAnnotationService ,
37
+ BookmarkViewService ,
38
+ MagnificationService ,
39
+ ThumbnailViewService ,
40
+ ToolbarService ,
41
+ NavigationService ,
42
+ AnnotationService ,
43
+ TextSearchService ,
44
+ TextSelectionService ,
45
+ FormFieldsService ,
46
+ FormDesignerService ,
47
+ PrintService
48
+ ]
49
+ } )
50
+ export class AppComponent implements OnInit {
51
+ public document : string = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf' ;
52
+ public resource : string = 'https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib' ;
53
+ pdfViewerComponent : any ;
54
+
55
+ ngOnInit ( ) : void {
56
+ }
57
+
58
+ handleSearch ( ) {
59
+ var pdfviewer = ( < any > document . getElementById ( "pdfViewer" ) ) . ej2_instances [ 0 ] ;
60
+ pdfviewer . textSearchModule . searchText ( 'PDF' , false ) ;
61
+ }
62
+
63
+ handleSearchNext ( ) {
64
+ var pdfviewer = ( < any > document . getElementById ( "pdfViewer" ) ) . ej2_instances [ 0 ] ;
65
+ pdfviewer . textSearchModule . searchNext ( ) ;
66
+ }
67
+
68
+ handleCancelSearch ( ) {
69
+ var pdfviewer = ( < any > document . getElementById ( "pdfViewer" ) ) . ej2_instances [ 0 ] ;
70
+ pdfviewer . textSearchModule . cancelTextSearch ( ) ;
71
+ }
72
+
73
+ handleTextSearchHighlight ( args : any ) {
74
+ var pdfviewer = ( < any > document . getElementById ( "pdfViewer" ) ) . ej2_instances [ 0 ] ;
75
+ console . log ( args ) ;
76
+ const bounds = args . bounds ;
77
+ pdfviewer . annotationModule . addAnnotation ( 'Rectangle' , {
78
+ pageNumber : args . pageNumber ,
79
+ offset : { x : bounds . left , y : bounds . top } ,
80
+ width : bounds . width ,
81
+ height : bounds . height ,
82
+ } ) ;
83
+ }
84
+ }
0 commit comments