@solidexpert/ngx-pdf-viewer 0.0.0-stage → 22.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,3 +1,550 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<h1 align="center">@solidexpert/ngx-pdf-viewer</h1>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://www.npmjs.com/package/@solidexpert/ngx-pdf-viewer">
|
|
4
|
+
<img src="https://img.shields.io/npm/v/@solidexpert/ngx-pdf-viewer.svg?style=flat" alt="npm version">
|
|
5
|
+
</a>
|
|
6
|
+
<a href="https://github.com/VadimDez/ng2-pdf-viewer">
|
|
7
|
+
<img src="https://img.shields.io/badge/fork-VadimDez%2Fng2--pdf--viewer-blue.svg" alt="Fork of VadimDez/ng2-pdf-viewer">
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
> PDF viewer component for Angular 22. Maintained by [solidexpert-ltd](https://github.com/solidexpert-ltd).
|
|
12
|
+
|
|
13
|
+
This package is a maintained fork of [VadimDez/ng2-pdf-viewer](https://github.com/VadimDez/ng2-pdf-viewer) by Vadym Yatsyuk. The original MIT copyright is unchanged. The npm name is `@solidexpert/ngx-pdf-viewer`, not `ng2-pdf-viewer`.
|
|
14
|
+
|
|
15
|
+
The viewer uses the public [PDF.js](https://github.com/mozilla/pdf.js) API from `pdfjs-dist` **4.8.69** (`getDocument`, `GlobalWorkerOptions`, `VerbosityLevel`, and `pdfjs-dist/web/pdf_viewer`). That is the version this fork builds with Angular 22.3.0.
|
|
16
|
+
|
|
17
|
+
### Demo page
|
|
18
|
+
|
|
19
|
+
[https://vadimdez.github.io/ng2-pdf-viewer/](https://vadimdez.github.io/ng2-pdf-viewer/)
|
|
20
|
+
|
|
21
|
+
#### Stackblitz Example
|
|
22
|
+
|
|
23
|
+
[https://stackblitz.com/edit/ng2-pdf-viewer](https://stackblitz.com/edit/ng2-pdf-viewer)
|
|
24
|
+
|
|
25
|
+
### Blog post
|
|
26
|
+
|
|
27
|
+
[https://medium.com/@vadimdez/render-pdf-in-angular-4-927e31da9c76](https://medium.com/@vadimdez/render-pdf-in-angular-4-927e31da9c76)
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
* [Install](#install)
|
|
32
|
+
* [Usage](#usage)
|
|
33
|
+
* [Options](#options)
|
|
34
|
+
* [Render local PDF file](#render-local-pdf-file)
|
|
35
|
+
* [Set custom path to the worker](#set-custom-path-to-the-worker)
|
|
36
|
+
* [Search in the PDF](#search-in-the-pdf)
|
|
37
|
+
* [Contribute](#contribute)
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
Angular 22:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
npm install @solidexpert/ngx-pdf-viewer
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Peers: `@angular/core` and `@angular/common` `^22`, `rxjs` `^7.8.2`.
|
|
48
|
+
|
|
49
|
+
Older Angular apps should stay on the original [`ng2-pdf-viewer`](https://github.com/VadimDez/ng2-pdf-viewer) releases.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
Add ```PdfViewerModule``` to your module's ```imports```
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { NgModule } from '@angular/core';
|
|
57
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
58
|
+
import { AppComponent } from './app/app.component';
|
|
59
|
+
|
|
60
|
+
import { PdfViewerModule } from '@solidexpert/ngx-pdf-viewer';
|
|
61
|
+
|
|
62
|
+
@NgModule({
|
|
63
|
+
imports: [BrowserModule, PdfViewerModule],
|
|
64
|
+
declarations: [AppComponent],
|
|
65
|
+
bootstrap: [AppComponent]
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
class AppModule {}
|
|
69
|
+
|
|
70
|
+
platformBrowserDynamic().bootstrapModule(AppModule);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
And then use it in your component
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { Component } from '@angular/core';
|
|
77
|
+
|
|
78
|
+
@Component({
|
|
79
|
+
selector: 'example-app',
|
|
80
|
+
template: `
|
|
81
|
+
<pdf-viewer [src]="pdfSrc"
|
|
82
|
+
[render-text]="true"
|
|
83
|
+
[original-size]="false"
|
|
84
|
+
style="width: 400px; height: 500px"
|
|
85
|
+
></pdf-viewer>
|
|
86
|
+
`
|
|
87
|
+
})
|
|
88
|
+
export class AppComponent {
|
|
89
|
+
pdfSrc = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Options
|
|
94
|
+
|
|
95
|
+
* [[src]](#src)
|
|
96
|
+
* [[(page)]](#page)
|
|
97
|
+
* [[stick-to-page]](#stick-to-page)
|
|
98
|
+
* [[external-link-target]](#external-link-target)
|
|
99
|
+
* [[render-text]](#render-text)
|
|
100
|
+
* [[render-text-mode]](#render-text-mode)
|
|
101
|
+
* [[rotation]](#rotation)
|
|
102
|
+
* [[zoom]](#zoom)
|
|
103
|
+
* [[zoom-scale]](#zoom-scale)
|
|
104
|
+
* [[original-size]](#original-size)
|
|
105
|
+
* [[fit-to-page]](#fit-to-page)
|
|
106
|
+
* [[show-all]](#show-all)
|
|
107
|
+
* [[autoresize]](#autoresize)
|
|
108
|
+
* [[c-maps-url]](#c-maps-url)
|
|
109
|
+
* [[show-borders]](#show-borders)
|
|
110
|
+
* [(after-load-complete)](#after-load-complete)
|
|
111
|
+
* [(page-rendered)](#page-rendered)
|
|
112
|
+
* [(text-layer-rendered)](#text-layer-rendered)
|
|
113
|
+
* [(error)](#error)
|
|
114
|
+
* [(on-progress)](#on-progress)
|
|
115
|
+
|
|
116
|
+
#### [src]
|
|
117
|
+
|
|
118
|
+
| Property | Type | Required |
|
|
119
|
+
| --- | ---- | --- |
|
|
120
|
+
| [src] | *string, object, UInt8Array* | Required |
|
|
121
|
+
|
|
122
|
+
Pass pdf location
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
[src]="'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf'"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
For more control you can pass options object to ```[src]```. [See other attributes for the object here](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L130-L222).
|
|
129
|
+
|
|
130
|
+
Options object for loading protected PDF would be:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
{
|
|
134
|
+
url: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
|
|
135
|
+
withCredentials: true
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### [page]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
| Property | Type | Required |
|
|
143
|
+
| --- | ---- | --- |
|
|
144
|
+
| [page] or [(page)] | *number* | *Required* with [show-all]="false" or *Optional* with [show-all]="true" |
|
|
145
|
+
|
|
146
|
+
Page number
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
[page]="1"
|
|
150
|
+
```
|
|
151
|
+
supports two way data binding as well
|
|
152
|
+
```
|
|
153
|
+
[(page)]="pageVariable"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
If you want that the `two way data binding` actually updates your `page` variable on page change/scroll - you have to be sure that you define the height of the container, for example:
|
|
157
|
+
```css
|
|
158
|
+
pdf-viewer {
|
|
159
|
+
height: 100vh;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### [stick-to-page]
|
|
164
|
+
|
|
165
|
+
| Property | Type | Required |
|
|
166
|
+
| --- | ---- | --- |
|
|
167
|
+
| [stick-to-page] | *boolean* | *Optional* |
|
|
168
|
+
|
|
169
|
+
Sticks view to the page. Works in combination with `[show-all]="true"` and `page`.
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
[stick-to-page]="true"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### [render-text]
|
|
176
|
+
|
|
177
|
+
| Property | Type | Required |
|
|
178
|
+
| --- | ---- | --- |
|
|
179
|
+
| [render-text] | *boolean* | *Optional* |
|
|
180
|
+
|
|
181
|
+
Enable text rendering, allows to select text
|
|
182
|
+
```
|
|
183
|
+
[render-text]="true"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### [render-text-mode]
|
|
187
|
+
|
|
188
|
+
| Property | Type | Required |
|
|
189
|
+
| --- | ---- | --- |
|
|
190
|
+
| [render-text-mode] | *RenderTextMode* | *Optional* |
|
|
191
|
+
|
|
192
|
+
Used in combination with `[render-text]="true"`
|
|
193
|
+
|
|
194
|
+
Controls if the text layer is enabled, and the selection mode that is used.
|
|
195
|
+
|
|
196
|
+
`0 = RenderTextMode.DISABLED` - disable the text selection layer
|
|
197
|
+
|
|
198
|
+
`1 = RenderTextMode.ENABLED` - enables the text selection layer
|
|
199
|
+
|
|
200
|
+
`2 = RenderTextMode.ENHANCED` - enables enhanced text selection
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
[render-text-mode]="1"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### [external-link-target]
|
|
207
|
+
|
|
208
|
+
| Property | Type | Required |
|
|
209
|
+
| --- | ---- | --- |
|
|
210
|
+
| [external-link-target] | *string* | *Optional* |
|
|
211
|
+
|
|
212
|
+
Used in combination with `[render-text]="true"`
|
|
213
|
+
|
|
214
|
+
Link target
|
|
215
|
+
* `blank`
|
|
216
|
+
* `none`
|
|
217
|
+
* `self`
|
|
218
|
+
* `parent`
|
|
219
|
+
* `top`
|
|
220
|
+
```
|
|
221
|
+
[external-link-target]="'blank'"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### [rotation]
|
|
225
|
+
|
|
226
|
+
| Property | Type | Required |
|
|
227
|
+
| --- | ---- | --- |
|
|
228
|
+
| [rotation] | *number* | *Optional* |
|
|
229
|
+
|
|
230
|
+
Rotate PDF
|
|
231
|
+
|
|
232
|
+
*Allowed step is 90 degree, ex. 0, 90, 180*
|
|
233
|
+
```
|
|
234
|
+
[rotation]="90"
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### [zoom]
|
|
238
|
+
|
|
239
|
+
| Property | Type | Required |
|
|
240
|
+
| --- | ---- | --- |
|
|
241
|
+
| [zoom] | *number* | *Optional* |
|
|
242
|
+
|
|
243
|
+
Zoom pdf
|
|
244
|
+
```
|
|
245
|
+
[zoom]="0.5"
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### [zoom-scale]
|
|
249
|
+
|
|
250
|
+
| Property | Type | Required |
|
|
251
|
+
| --- | ---- | --- |
|
|
252
|
+
| [zoom-scale] | *'page-width'\|'page-fit'\|'page-height'* | *Optional* |
|
|
253
|
+
|
|
254
|
+
Defines how the Zoom scale is computed when `[original-size]="false"`, by default set to 'page-width'.
|
|
255
|
+
|
|
256
|
+
- *'page-width'* with zoom of 1 will display a page width that take all the possible horizontal space in the container
|
|
257
|
+
|
|
258
|
+
- *'page-height'* with zoom of 1 will display a page height that take all the possible vertical space in the container
|
|
259
|
+
|
|
260
|
+
- *'page-fit'* with zoom of 1 will display a page that will be scaled to either width or height to fit completely in the container
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
[zoom-scale]="'page-width'"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
#### [original-size]
|
|
267
|
+
|
|
268
|
+
| Property | Type | Required |
|
|
269
|
+
| --- | ---- | --- |
|
|
270
|
+
| [original-size] | *boolean* | *Optional* |
|
|
271
|
+
|
|
272
|
+
* if set to *true* - size will be as same as original document
|
|
273
|
+
* if set to *false* - size will be as same as container block
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
[original-size]="true"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### [fit-to-page]
|
|
280
|
+
|
|
281
|
+
| Property | Type | Required |
|
|
282
|
+
| --- | ---- | --- |
|
|
283
|
+
| [fit-to-page] | *boolean* | *Optional* |
|
|
284
|
+
|
|
285
|
+
Works in combination with `[original-size]="true"`. You can show your document in original size, and make sure that it's not bigger then container block.
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
[fit-to-page]="false"
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### [show-all]
|
|
292
|
+
|
|
293
|
+
| Property | Type | Required |
|
|
294
|
+
| --- | ---- | --- |
|
|
295
|
+
| [show-all] | *boolean* | *Optional* |
|
|
296
|
+
|
|
297
|
+
Show single or all pages altogether
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
[show-all]="true"
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### [autoresize]
|
|
304
|
+
|
|
305
|
+
| Property | Type | Required |
|
|
306
|
+
| --- | ---- | --- |
|
|
307
|
+
| [autoresize] | *boolean* | *Optional* |
|
|
308
|
+
|
|
309
|
+
Turn on or off auto resize.
|
|
310
|
+
|
|
311
|
+
**!Important** To make `[autoresize]` work - make sure that `[original-size]="false"` and `pdf-viewer` tag has `max-width` or `display` are set.
|
|
312
|
+
|
|
313
|
+
```
|
|
314
|
+
[autoresize]="true"
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### [c-maps-url]
|
|
318
|
+
|
|
319
|
+
| Property | Type | Required |
|
|
320
|
+
| --- | ---- | --- |
|
|
321
|
+
| [c-maps-url] | *string* | Optional |
|
|
322
|
+
|
|
323
|
+
Url for non-latin characters source maps.
|
|
324
|
+
```
|
|
325
|
+
[c-maps-url]="'assets/cmaps/'"
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
Default url is: [https://unpkg.com/pdfjs-dist@2.0.550/cmaps/](https://unpkg.com/pdfjs-dist@2.0.550/cmaps/)
|
|
329
|
+
|
|
330
|
+
To serve cmaps on your own you need to copy ```node_modules/pdfjs-dist/cmaps``` to ```assets/cmaps```.
|
|
331
|
+
|
|
332
|
+
### [show-borders]
|
|
333
|
+
|
|
334
|
+
| Property | Type | Required |
|
|
335
|
+
| --- | ---- | --- |
|
|
336
|
+
| [show-borders] | *boolean* | Optional |
|
|
337
|
+
|
|
338
|
+
Show page borders
|
|
339
|
+
```
|
|
340
|
+
[show-borders]="true"
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
#### (after-load-complete)
|
|
344
|
+
|
|
345
|
+
| Property | Type | Required |
|
|
346
|
+
| --- | ---- | --- |
|
|
347
|
+
| (after-load-complete) | *callback* | *Optional* |
|
|
348
|
+
|
|
349
|
+
Get PDF information with callback
|
|
350
|
+
|
|
351
|
+
First define callback function "callBackFn" in your controller,
|
|
352
|
+
```typescript
|
|
353
|
+
callBackFn(pdf: PDFDocumentProxy) {
|
|
354
|
+
// do anything with "pdf"
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
And then use it in your template:
|
|
359
|
+
```
|
|
360
|
+
(after-load-complete)="callBackFn($event)"
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
#### (page-rendered)
|
|
364
|
+
|
|
365
|
+
| Property | Type | Required |
|
|
366
|
+
| --- | ---- | --- |
|
|
367
|
+
| (page-rendered) | *callback* | *Optional* |
|
|
368
|
+
|
|
369
|
+
Get event when a page is rendered. Called for every page rendered.
|
|
370
|
+
|
|
371
|
+
Define callback in your component:
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
pageRendered(e: CustomEvent) {
|
|
375
|
+
console.log('(page-rendered)', e);
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
And then bind it to `<pdf-viewer>`:
|
|
380
|
+
|
|
381
|
+
```angular2html
|
|
382
|
+
(page-rendered)="pageRendered($event)"
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### (pages-initialized)
|
|
386
|
+
|
|
387
|
+
| Property | Type | Required |
|
|
388
|
+
| --- | ---- | --- |
|
|
389
|
+
| (pages-initialized) | *callback* | *Optional* |
|
|
390
|
+
|
|
391
|
+
Get event when the pages are initialized.
|
|
392
|
+
|
|
393
|
+
Define callback in your component:
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
pageInitialized(e: CustomEvent) {
|
|
397
|
+
console.log('(pages-initialized)', e);
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
And then bind it to `<pdf-viewer>`:
|
|
402
|
+
|
|
403
|
+
```angular2html
|
|
404
|
+
(pages-initialized)="pageInitialized($event)"
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
#### (text-layer-rendered)
|
|
408
|
+
|
|
409
|
+
| Property | Type | Required |
|
|
410
|
+
| --- | ---- | --- |
|
|
411
|
+
| (text-layer-rendered) | *callback* | *Optional* |
|
|
412
|
+
|
|
413
|
+
Get event when a text layer is rendered.
|
|
414
|
+
|
|
415
|
+
Define callback in your component:
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
textLayerRendered(e: CustomEvent) {
|
|
419
|
+
console.log('(text-layer-rendered)', e);
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
And then bind it to `<pdf-viewer>`:
|
|
424
|
+
|
|
425
|
+
```angular2html
|
|
426
|
+
(text-layer-rendered)="textLayerRendered($event)"
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### (error)
|
|
430
|
+
|
|
431
|
+
| Property | Type | Required |
|
|
432
|
+
| --- | ---- | --- |
|
|
433
|
+
| (error) | *callback* | *Optional* |
|
|
434
|
+
|
|
435
|
+
Error handling callback
|
|
436
|
+
|
|
437
|
+
Define callback in your component's class
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
onError(error: any) {
|
|
441
|
+
// do anything
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Then add it to `pdf-component` in component's template
|
|
446
|
+
|
|
447
|
+
```html
|
|
448
|
+
(error)="onError($event)"
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
#### (on-progress)
|
|
452
|
+
|
|
453
|
+
| Property | Type | Required |
|
|
454
|
+
| --- | ---- | --- |
|
|
455
|
+
| (on-progress) | *callback* | *Optional* |
|
|
456
|
+
|
|
457
|
+
Loading progress callback - provides progress information `total` and `loaded` bytes. Is called several times during pdf loading phase.
|
|
458
|
+
|
|
459
|
+
Define callback in your component's class
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
onProgress(progressData: PDFProgressData) {
|
|
463
|
+
// do anything with progress data. For example progress indicator
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
Then add it to `pdf-component` in component's template
|
|
468
|
+
|
|
469
|
+
```html
|
|
470
|
+
(on-progress)="onProgress($event)"
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
## Render local PDF file
|
|
474
|
+
|
|
475
|
+
In your `html` template add `input`:
|
|
476
|
+
|
|
477
|
+
```html
|
|
478
|
+
<input (change)="onFileSelected()" type="file" id="file">
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
and then add `onFileSelected` method to your component:
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
onFileSelected() {
|
|
485
|
+
let $img: any = document.querySelector('#file');
|
|
486
|
+
|
|
487
|
+
if (typeof (FileReader) !== 'undefined') {
|
|
488
|
+
let reader = new FileReader();
|
|
489
|
+
|
|
490
|
+
reader.onload = (e: any) => {
|
|
491
|
+
this.pdfSrc = e.target.result;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
reader.readAsArrayBuffer($img.files[0]);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
## Set custom path to the worker
|
|
501
|
+
|
|
502
|
+
By default the `worker` is loaded from `cdn.jsdelivr.net`.
|
|
503
|
+
|
|
504
|
+
In your code update `path` to the worker to be for example `/pdf.worker.mjs`
|
|
505
|
+
```typescript
|
|
506
|
+
(window as any).pdfWorkerSrc = '/pdf.worker.mjs';
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
*This should be set before `pdf-viewer` component is rendered.*
|
|
510
|
+
|
|
511
|
+
If you ever have a (super rare) edge case where you run in an environment that multiple
|
|
512
|
+
components are somehow loaded within the same web page, sharing the same window,
|
|
513
|
+
but using different versions of pdf.worker, support has been added. You can do the
|
|
514
|
+
above, except that you can append the specific version of pdfjs required and override the
|
|
515
|
+
custom path *just for that version*. This way setting the global window var won't conflict.
|
|
516
|
+
```typescript
|
|
517
|
+
(window as any)["pdfWorkerSrc2.14.305"] = '/pdf.worker.mjs';
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
## Search in the PDF
|
|
521
|
+
|
|
522
|
+
Use `eventBus` for the search functionality.
|
|
523
|
+
|
|
524
|
+
In your component's ts file:
|
|
525
|
+
|
|
526
|
+
* Add reference to `pdf-viewer` component,
|
|
527
|
+
* then when needed execute `search()` like this:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;
|
|
531
|
+
|
|
532
|
+
search(stringToSearch: string) {
|
|
533
|
+
this.pdfComponent.eventBus.dispatch('find', {
|
|
534
|
+
query: stringToSearch, type: 'again', caseSensitive: false, findPrevious: undefined, highlightAll: true, phraseSearch: true
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
## Contribute
|
|
540
|
+
[See CONTRIBUTING.md](CONTRIBUTING.md)
|
|
541
|
+
|
|
542
|
+
## Donation
|
|
543
|
+
If this project help you reduce time to develop, you can give me a cup of tea :)
|
|
544
|
+
|
|
545
|
+
[](https://www.paypal.me/vadimdez)
|
|
546
|
+
|
|
547
|
+
## License
|
|
548
|
+
|
|
549
|
+
[MIT](https://tldrlegal.com/license/mit-license) © [Vadym Yatsyuk](https://github.com/vadimdez)
|
|
550
|
+
|