ng2-pdfjs-viewer 25.0.9 → 25.0.10
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 +137 -3
- package/fesm2022/ng2-pdfjs-viewer.mjs +261 -196
- package/fesm2022/ng2-pdfjs-viewer.mjs.map +1 -1
- package/index.d.ts +24 -1
- package/package.json +1 -1
- package/pdfjs/web/ng2-customization.css +305 -0
- package/pdfjs/web/postmessage-wrapper.js +1966 -2144
- package/pdfjs/web/viewer.html +2 -4
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ Whether you need a simple embedded PDF viewer or a complex document management s
|
|
|
57
57
|
| **Enhanced Error Handling** | Multiple error display styles with custom templates | ✅ New |
|
|
58
58
|
| **Mobile-First Design** | Responsive layout optimized for touch devices | ✅ New |
|
|
59
59
|
| **TypeScript Strict Mode** | Full type safety with comprehensive API coverage | ✅ New |
|
|
60
|
+
| **URL Security Validation** | Prevents unauthorized file parameter manipulation with custom templates | ✅ New |
|
|
60
61
|
|
|
61
62
|
### 🏆 Unique Advantages
|
|
62
63
|
|
|
@@ -197,6 +198,13 @@ Add PDF.js assets to your `angular.json`:
|
|
|
197
198
|
- **🔄 Rotation & Zoom** - Document manipulation with smooth animations
|
|
198
199
|
- **📱 Touch Gestures** - Mobile-optimized touch interactions
|
|
199
200
|
|
|
201
|
+
### 🔒 Security Features
|
|
202
|
+
|
|
203
|
+
- **CSP Compliant** - Works with strict Content Security Policy (`style-src 'self'`)
|
|
204
|
+
- **URL Validation** - Prevents unauthorized file parameter manipulation in external viewer
|
|
205
|
+
- **Custom Security Templates** - Angular template support for security warnings
|
|
206
|
+
- **Console Warnings** - Developer-friendly security notifications
|
|
207
|
+
|
|
200
208
|
---
|
|
201
209
|
|
|
202
210
|
## 📦 Installation
|
|
@@ -207,6 +215,21 @@ Add PDF.js assets to your `angular.json`:
|
|
|
207
215
|
- **Node.js**: 18.0+
|
|
208
216
|
- **TypeScript**: 5.0+
|
|
209
217
|
|
|
218
|
+
### Production Deployment
|
|
219
|
+
|
|
220
|
+
#### Nginx Configuration
|
|
221
|
+
|
|
222
|
+
For production deployments using nginx, you may need to configure MIME types for PDF.js ES modules (`.mjs` files):
|
|
223
|
+
|
|
224
|
+
```nginx
|
|
225
|
+
# Add to your nginx.conf or site configuration
|
|
226
|
+
types {
|
|
227
|
+
application/javascript js mjs;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Why this is needed**: PDF.js v5+ uses `.mjs` files (ES modules). Without proper MIME type configuration, nginx serves these files with incorrect content-type headers, causing the PDF viewer to crash during loading in production environments.
|
|
232
|
+
|
|
210
233
|
### Angular Version Support
|
|
211
234
|
|
|
212
235
|
| Angular Version | Support Level | Notes |
|
|
@@ -284,6 +307,31 @@ Add PDF.js assets to your `angular.json`:
|
|
|
284
307
|
</ng2-pdfjs-viewer>
|
|
285
308
|
```
|
|
286
309
|
|
|
310
|
+
### Security Configuration
|
|
311
|
+
|
|
312
|
+
```html
|
|
313
|
+
<!-- Basic security (default enabled) -->
|
|
314
|
+
<ng2-pdfjs-viewer
|
|
315
|
+
pdfSrc="assets/document.pdf"
|
|
316
|
+
[urlValidation]="true">
|
|
317
|
+
</ng2-pdfjs-viewer>
|
|
318
|
+
|
|
319
|
+
<!-- Custom security template -->
|
|
320
|
+
<ng2-pdfjs-viewer
|
|
321
|
+
pdfSrc="assets/document.pdf"
|
|
322
|
+
[urlValidation]="true"
|
|
323
|
+
[customSecurityTpl]="securityTemplate">
|
|
324
|
+
</ng2-pdfjs-viewer>
|
|
325
|
+
|
|
326
|
+
<ng-template #securityTemplate let-warning="securityWarning">
|
|
327
|
+
<div class="alert alert-warning" *ngIf="warning">
|
|
328
|
+
<h4>⚠️ Security Warning</h4>
|
|
329
|
+
<p>{{ warning.message }}</p>
|
|
330
|
+
<button (click)="pdfViewer.dismissSecurityWarning()">Dismiss</button>
|
|
331
|
+
</div>
|
|
332
|
+
</ng-template>
|
|
333
|
+
```
|
|
334
|
+
|
|
287
335
|
### Programmatic Control
|
|
288
336
|
|
|
289
337
|
```typescript
|
|
@@ -364,6 +412,84 @@ export class MyComponent {
|
|
|
364
412
|
</ng2-pdfjs-viewer>
|
|
365
413
|
```
|
|
366
414
|
|
|
415
|
+
### External Window Behavior
|
|
416
|
+
|
|
417
|
+
```html
|
|
418
|
+
<!-- Basic external window (reuses same tab) -->
|
|
419
|
+
<ng2-pdfjs-viewer
|
|
420
|
+
pdfSrc="document.pdf"
|
|
421
|
+
[externalWindow]="true">
|
|
422
|
+
</ng2-pdfjs-viewer>
|
|
423
|
+
|
|
424
|
+
<!-- Custom window options -->
|
|
425
|
+
<ng2-pdfjs-viewer
|
|
426
|
+
pdfSrc="document.pdf"
|
|
427
|
+
[externalWindow]="true"
|
|
428
|
+
[externalWindowOptions]="'width=1200,height=800,scrollbars=yes,resizable=yes'">
|
|
429
|
+
</ng2-pdfjs-viewer>
|
|
430
|
+
|
|
431
|
+
<!-- Force new tab each time -->
|
|
432
|
+
<ng2-pdfjs-viewer
|
|
433
|
+
pdfSrc="document.pdf"
|
|
434
|
+
[externalWindow]="true"
|
|
435
|
+
[target]="'pdf-viewer-' + Date.now()">
|
|
436
|
+
</ng2-pdfjs-viewer>
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Tab Reuse Behavior:**
|
|
440
|
+
- **Same `target` name** → Reuses existing tab (default behavior)
|
|
441
|
+
- **Unique `target` name** → Always opens new tab
|
|
442
|
+
- **`target="_blank"`** → Browser decides (usually reuses)
|
|
443
|
+
|
|
444
|
+
### iframe Security
|
|
445
|
+
|
|
446
|
+
```html
|
|
447
|
+
<!-- Built-in security (always enabled) -->
|
|
448
|
+
<ng2-pdfjs-viewer
|
|
449
|
+
pdfSrc="document.pdf">
|
|
450
|
+
</ng2-pdfjs-viewer>
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
**Built-in Security Features:**
|
|
454
|
+
- **Static Sandbox** - `allow-forms allow-scripts allow-same-origin allow-modals`
|
|
455
|
+
- **XSS Prevention** - Prevents malicious scripts from affecting parent page
|
|
456
|
+
- **CSP Compliance** - Meets Content Security Policy requirements
|
|
457
|
+
- **Data Protection** - Limits iframe access to parent window context
|
|
458
|
+
- **Enterprise Ready** - Suitable for corporate security environments
|
|
459
|
+
|
|
460
|
+
**Sandbox Attributes (Fixed for Security):**
|
|
461
|
+
- `allow-forms` - Required for PDF form functionality
|
|
462
|
+
- `allow-scripts` - Required for PDF.js JavaScript execution
|
|
463
|
+
- `allow-same-origin` - Required for loading PDF files and assets
|
|
464
|
+
- `allow-modals` - Required for PDF.js dialogs (print, download)
|
|
465
|
+
|
|
466
|
+
### iframe Styling
|
|
467
|
+
|
|
468
|
+
```html
|
|
469
|
+
<!-- Default (no border) -->
|
|
470
|
+
<ng2-pdfjs-viewer
|
|
471
|
+
pdfSrc="document.pdf">
|
|
472
|
+
</ng2-pdfjs-viewer>
|
|
473
|
+
|
|
474
|
+
<!-- Custom border -->
|
|
475
|
+
<ng2-pdfjs-viewer
|
|
476
|
+
pdfSrc="document.pdf"
|
|
477
|
+
iframeBorder="2px solid #ccc">
|
|
478
|
+
</ng2-pdfjs-viewer>
|
|
479
|
+
|
|
480
|
+
<!-- Numeric border -->
|
|
481
|
+
<ng2-pdfjs-viewer
|
|
482
|
+
pdfSrc="document.pdf"
|
|
483
|
+
[iframeBorder]="1">
|
|
484
|
+
</ng2-pdfjs-viewer>
|
|
485
|
+
|
|
486
|
+
<!-- No border (explicit) -->
|
|
487
|
+
<ng2-pdfjs-viewer
|
|
488
|
+
pdfSrc="document.pdf"
|
|
489
|
+
iframeBorder="0">
|
|
490
|
+
</ng2-pdfjs-viewer>
|
|
491
|
+
```
|
|
492
|
+
|
|
367
493
|
---
|
|
368
494
|
|
|
369
495
|
## 📚 API Reference
|
|
@@ -376,8 +502,8 @@ export class MyComponent {
|
|
|
376
502
|
| `viewerId` | `string` | auto | Unique viewer identifier |
|
|
377
503
|
| `viewerFolder` | `string` | `'assets'` | Path to PDF.js assets |
|
|
378
504
|
| `externalWindow` | `boolean` | `false` | Open in new window |
|
|
379
|
-
| `externalWindowOptions` | `string` | - | External window options
|
|
380
|
-
| `target` | `string` | `'_blank'` | Target for external window
|
|
505
|
+
| `externalWindowOptions` | `string` | - | External window options (size, position, etc.) |
|
|
506
|
+
| `target` | `string` | `'_blank'` | Target for external window (controls tab reuse) |
|
|
381
507
|
| `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Theme selection |
|
|
382
508
|
| `primaryColor` | `string` | `'#007acc'` | Primary color for UI elements |
|
|
383
509
|
| `backgroundColor` | `string` | `'#ffffff'` | Background color |
|
|
@@ -386,6 +512,8 @@ export class MyComponent {
|
|
|
386
512
|
| `textColor` | `string` | - | Text color |
|
|
387
513
|
| `borderRadius` | `string` | - | Border radius |
|
|
388
514
|
| `customCSS` | `string` | - | Custom CSS styles |
|
|
515
|
+
| `cspNonce` | `string` | - | CSP nonce for customCSS (optional) |
|
|
516
|
+
| `iframeTitle` | `string` | - | Accessible title for iframe (optional) |
|
|
389
517
|
| `showSpinner` | `boolean` | `true` | Show loading spinner |
|
|
390
518
|
| `customSpinnerTpl` | `TemplateRef` | - | Custom spinner template |
|
|
391
519
|
| `spinnerClass` | `string` | - | Custom spinner CSS class |
|
|
@@ -437,6 +565,10 @@ export class MyComponent {
|
|
|
437
565
|
| `themeConfig` | `ThemeConfig` | - | Theme configuration |
|
|
438
566
|
| `groupVisibility` | `GroupVisibilityConfig` | - | Group visibility configuration |
|
|
439
567
|
| `layoutConfig` | `LayoutConfig` | - | Layout configuration |
|
|
568
|
+
| `urlValidation` | `boolean` | `true` | Enable URL validation |
|
|
569
|
+
| `customSecurityTpl` | `TemplateRef<any>` | - | Custom security template |
|
|
570
|
+
| `securityWarning` | `SecurityWarning \| null` | - | Security warning data (read-only) |
|
|
571
|
+
| `iframeBorder` | `string \| number` | `"0"` | iframe border style |
|
|
440
572
|
|
|
441
573
|
### Output Events
|
|
442
574
|
|
|
@@ -491,6 +623,8 @@ export class MyComponent {
|
|
|
491
623
|
| `goBack()` | - | `void` | Go back in browser history |
|
|
492
624
|
| `closeViewer()` | - | `void` | Close viewer window |
|
|
493
625
|
| `getErrorTemplateData()` | - | `any` | Get error template data |
|
|
626
|
+
| `setUrlValidation(enabled: boolean)` | `enabled: boolean` | `Promise<ActionExecutionResult>` | Enable/disable URL validation |
|
|
627
|
+
| `dismissSecurityWarning()` | - | `void` | Dismiss security warning |
|
|
494
628
|
|
|
495
629
|
---
|
|
496
630
|
|
|
@@ -782,7 +916,7 @@ This project is licensed under the **Apache License 2.0 + Commons Clause License
|
|
|
782
916
|
- 💬 **Community**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
|
|
783
917
|
- 🐛 **Issues**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
|
|
784
918
|
- 📧 **Email**: codehippie1@gmail.com
|
|
785
|
-
-
|
|
919
|
+
- 👨💻 **Author**: [Aneesh Gopalakrishnan](http://github.com/codehippie1)
|
|
786
920
|
|
|
787
921
|
---
|
|
788
922
|
|