ng2-pdfjs-viewer 25.0.1 → 25.0.4

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.
Files changed (2) hide show
  1. package/README.md +732 -695
  2. package/package.json +25 -7
package/README.md CHANGED
@@ -1,695 +1,732 @@
1
- # Angular PDF viewer powered by Mozilla's PDF.js
2
-
3
- The most reliable, feature-rich Angular PDF viewer component powered by Mozilla's PDF.js
4
-
5
- <div align="center">
6
-
7
- [![NPM Version](https://img.shields.io/npm/v/ng2-pdfjs-viewer?logo=npm&color=blue)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
8
- [![PDF.js Version](https://img.shields.io/badge/PDF.js%20v5.3.93-latest-green?logo=mozilla)](https://github.com/mozilla/pdf.js)
9
- [![Angular Support](https://img.shields.io/badge/Angular%2020+-supported-red?logo=angular)](https://angular.dev/overview)
10
- [![NPM Downloads](https://img.shields.io/npm/dm/ng2-pdfjs-viewer?label=downloads%2Fmonth&color=orange)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
11
- [![Total Downloads](https://img.shields.io/badge/total%20downloads-7M+-brightgreen?logo=npm)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
12
- [![Since 2018](https://img.shields.io/badge/since-2018-blue?logo=calendar)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
13
- [![License](https://img.shields.io/badge/license-Apache%202.0%20%2B%20Commons%20Clause-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
14
- [![GitHub Stars](https://img.shields.io/github/stars/intbot/ng2-pdfjs-viewer?logo=github)](https://github.com/intbot/ng2-pdfjs-viewer)
15
- [![GitHub Issues](https://img.shields.io/github/issues/intbot/ng2-pdfjs-viewer?logo=github)](https://github.com/intbot/ng2-pdfjs-viewer/issues)
16
-
17
- </div>
18
-
19
- <div align="center">
20
-
21
- [**Live Demo**](https://ng2-pdfjs-viewer.azurewebsites.net) • [**API Reference**](#-api-reference) • [**Examples**](#-examples) • [**Migration Guide**](#-migration-guide)
22
-
23
- </div>
24
-
25
- ---
26
-
27
- ng2-pdfjs-viewer is the most comprehensive and feature-rich Angular PDF viewer component available. **Born in 2018** and still going strong with over **7+ million downloads**, this battle-tested library has been trusted by developers worldwide for **over 8 years**, powering thousands of applications.
28
-
29
- This powerful library enables developers to seamlessly integrate PDF viewing capabilities into Angular applications with enterprise-grade features, custom theming, and mobile-first responsive design. Built on Mozilla's PDF.js v5.3.93, ng2-pdfjs-viewer provides advanced PDF rendering, document navigation, search functionality, and extensive customization options.
30
-
31
- Whether you need a simple embedded PDF viewer or a complex document management system, this component delivers the performance and flexibility required for modern Angular applications. **The most mature and reliable Angular PDF viewer solution** with continuous updates and long-term support.
32
-
33
- ### Why Choose ng2-pdfjs-viewer?
34
-
35
- - **🚀 Always Up-to-Date** - Continuously updated with the latest PDF.js versions and Angular compatibility
36
- - **🏗️ Enterprise-Ready** - Built for production with comprehensive error handling and performance optimization
37
- - **🎨 Highly Customizable** - Extensive theming options, custom templates, and flexible configuration
38
- - **📱 Mobile Optimized** - Touch-friendly interface with responsive design for all screen sizes
39
- - **🔧 Developer Friendly** - Full TypeScript support, comprehensive documentation, and easy integration
40
- - **⚡ High Performance** - Event-driven architecture with efficient memory management and lazy loading
41
- - **🌍 Global Support** - Multi-language support with automatic locale detection and RTL compatibility
42
- - **🛡️ Production Tested** - Trusted by thousands of applications with millions of downloads
43
- - **📈 Proven Track Record** - 8+ years of continuous development and community support
44
- - **🔒 Security Focused** - Regular security updates and vulnerability patches
45
-
46
- ### 🆕 Latest Features (v25.x)
47
-
48
- | Feature | Description | Status |
49
- | ----------------------------- | ------------------------------------------------------------------ | ------ |
50
- | **Advanced Theme System** | CSS custom properties for complete visual customization | ✅ New |
51
- | **Template-Based UI** | Custom loading spinners and error displays using Angular templates | ✅ New |
52
- | **Convenience Configuration** | Object-based configuration for cleaner, more maintainable code | ✅ New |
53
- | **Event-Driven Architecture** | Pure event-based system with universal action dispatcher | ✅ New |
54
- | **Enhanced Error Handling** | Multiple error display styles with custom templates | ✅ New |
55
- | **Mobile-First Design** | Responsive layout optimized for touch devices | ✅ New |
56
- | **TypeScript Strict Mode** | Full type safety with comprehensive API coverage | ✅ New |
57
-
58
- ### 🏆 Unique Advantages
59
-
60
- - **Universal Action Dispatcher** - Single pathway for all actions with readiness validation
61
- - **Template-Based Customization** - Use Angular templates for loading and error states
62
- - **Comprehensive Event System** - 24+ events covering all user interactions and state changes
63
- - **Advanced Configuration Objects** - Clean, object-based configuration for complex setups
64
- - **Production-Ready Architecture** - Event-driven design with no timeouts or polling
65
- - **Complete API Coverage** - 19+ methods with consistent Promise-based returns
66
-
67
- ### 🎯 Perfect For
68
-
69
- - **Enterprise Applications** - Robust, scalable PDF viewing for business applications
70
- - **Document Management Systems** - Complete PDF handling with search and navigation
71
- - **E-Learning Platforms** - Interactive PDF viewing for educational content
72
- - **Financial Applications** - Secure PDF viewing for reports and statements
73
- - **Healthcare Systems** - Reliable PDF viewing for medical documents
74
- - **Government Portals** - Accessible PDF viewing for public services
75
- - **E-Commerce Platforms** - Product catalogs and documentation viewing
76
- - **Content Management Systems** - Integrated PDF viewing and management
77
-
78
- ---
79
-
80
- ## 📋 Table of Contents
81
-
82
- - [Quick Start](#quick-start)
83
- - [Features](#features)
84
- - [Installation](#installation)
85
- - [Basic Usage](#basic-usage)
86
- - [Advanced Configuration](#advanced-configuration)
87
- - [API Reference](#api-reference)
88
- - [Examples](#examples)
89
- - [Migration Guide](#migration-guide)
90
- - [Deprecated Features](#deprecated-features)
91
- - [Contributing](#contributing)
92
- - [License](#license)
93
-
94
- ---
95
-
96
- ## 🚀 Quick Start
97
-
98
- ### 1. Install the Package
99
-
100
- ```bash
101
- npm install ng2-pdfjs-viewer --save
102
- ```
103
-
104
- ### 2. Import the Module
105
-
106
- ```typescript
107
- import { NgModule } from "@angular/core";
108
- import { BrowserModule } from "@angular/platform-browser";
109
- import { PdfJsViewerModule } from "ng2-pdfjs-viewer";
110
-
111
- @NgModule({
112
- imports: [BrowserModule, PdfJsViewerModule],
113
- // ... rest of your module
114
- })
115
- export class AppModule {}
116
- ```
117
-
118
- ### 3. Use in Your Component
119
-
120
- ```html
121
- <ng2-pdfjs-viewer
122
- pdfSrc="assets/sample.pdf"
123
- [showSpinner]="true"
124
- [theme]="'light'"
125
- >
126
- </ng2-pdfjs-viewer>
127
- ```
128
-
129
- ### 4. Configure Assets (Required)
130
-
131
- Add PDF.js assets to your `angular.json`:
132
-
133
- ```json
134
- {
135
- "projects": {
136
- "your-app": {
137
- "architect": {
138
- "build": {
139
- "options": {
140
- "assets": [
141
- {
142
- "glob": "**/*",
143
- "input": "node_modules/ng2-pdfjs-viewer/pdfjs",
144
- "output": "/assets/pdfjs"
145
- }
146
- ]
147
- }
148
- }
149
- }
150
- }
151
- }
152
- }
153
- ```
154
-
155
- ---
156
-
157
- ## ✨ Features
158
-
159
- **🎉 7+ Million Downloads & Counting!** - Trusted by developers worldwide for reliable PDF viewing in Angular applications since 2018.
160
-
161
- ### 🎯 Core PDF Viewing Features
162
-
163
- - **📄 High-Quality PDF Rendering** - Powered by Mozilla's PDF.js v5.3.93 for superior document display
164
- - **🔄 Multiple Display Modes** - Embedded viewer, new window, or external tab options
165
- - **📱 Mobile-First Responsive Design** - Touch-friendly controls optimized for all devices
166
- - **🌍 Complete Internationalization** - Support for 50+ languages with automatic locale detection
167
- - **⚡ Optimized Performance** - Lazy loading, memory management, and efficient rendering
168
-
169
- ### 🎨 Visual Customization
170
-
171
- - **🎨 Theme System** - Light, dark, and auto themes with custom color schemes
172
- - **🎭 Custom Styling** - CSS custom properties for complete visual control
173
- - **🔄 Loading States** - Custom loading spinners with template support
174
- - **❌ Error Handling** - Multiple error display styles with custom templates
175
- - **📐 Layout Control** - Toolbar density, sidebar width, and positioning options
176
-
177
- ### 🔧 Developer Features
178
-
179
- - **📝 TypeScript Support** - Full type safety with strict mode
180
- - **🔌 Event System** - Comprehensive event handling for all user interactions
181
- - **⚙️ Configuration Objects** - Convenience setters for cleaner code
182
- - **🛠️ API Methods** - Promise-based methods for programmatic control
183
- - **🐛 Debugging** - Built-in diagnostic logging and error tracking
184
-
185
- ### 📊 Advanced Features
186
-
187
- - **🔍 Search & Navigation** - Full-text search with highlighting
188
- - **📖 Bookmarks & Attachments** - Document structure navigation
189
- - **🖨️ Print & Download** - Built-in print and download functionality
190
- - **🔄 Rotation & Zoom** - Document manipulation with smooth animations
191
- - **📱 Touch Gestures** - Mobile-optimized touch interactions
192
-
193
- ---
194
-
195
- ## 📦 Installation
196
-
197
- ### Prerequisites
198
-
199
- - Angular 20.0+ (supports Angular 2.0+)
200
- - Node.js 18.0+
201
- - TypeScript 5.0+
202
-
203
- ### Install Package
204
-
205
- ```bash
206
- # Using npm
207
- npm install ng2-pdfjs-viewer --save
208
-
209
- # Using yarn
210
- yarn add ng2-pdfjs-viewer
211
-
212
- # Using pnpm
213
- pnpm add ng2-pdfjs-viewer
214
- ```
215
-
216
- ### Configure Assets
217
-
218
- Add PDF.js assets to your `angular.json`:
219
-
220
- ```json
221
- {
222
- "projects": {
223
- "your-app": {
224
- "architect": {
225
- "build": {
226
- "options": {
227
- "assets": [
228
- {
229
- "glob": "**/*",
230
- "input": "node_modules/ng2-pdfjs-viewer/pdfjs",
231
- "output": "/assets/pdfjs"
232
- }
233
- ]
234
- }
235
- }
236
- }
237
- }
238
- }
239
- }
240
- ```
241
-
242
- ---
243
-
244
- ## 🎯 Basic Usage
245
-
246
- ### Simple PDF Viewer
247
-
248
- ```html
249
- <ng2-pdfjs-viewer pdfSrc="assets/document.pdf" [showSpinner]="true">
250
- </ng2-pdfjs-viewer>
251
- ```
252
-
253
- ### Advanced Configuration
254
-
255
- ```html
256
- <ng2-pdfjs-viewer
257
- pdfSrc="assets/document.pdf"
258
- [theme]="'dark'"
259
- [primaryColor]="'#007acc'"
260
- [showSpinner]="true"
261
- [customSpinnerTpl]="customSpinner"
262
- [customErrorTpl]="customError"
263
- (onDocumentLoad)="onDocumentLoaded($event)"
264
- (onPageChange)="onPageChanged($event)"
265
- >
266
- </ng2-pdfjs-viewer>
267
- ```
268
-
269
- ### Programmatic Control
270
-
271
- ```typescript
272
- import { Component, ViewChild } from "@angular/core";
273
- import { PdfJsViewerComponent } from "ng2-pdfjs-viewer";
274
-
275
- @Component({
276
- template: `
277
- <ng2-pdfjs-viewer #pdfViewer pdfSrc="document.pdf"></ng2-pdfjs-viewer>
278
- <button (click)="goToPage(5)">Go to Page 5</button>
279
- `,
280
- })
281
- export class MyComponent {
282
- @ViewChild("pdfViewer") pdfViewer!: PdfJsViewerComponent;
283
-
284
- async goToPage(page: number) {
285
- await this.pdfViewer.goToPage(page);
286
- }
287
- }
288
- ```
289
-
290
- ---
291
-
292
- ## ⚙️ Advanced Configuration
293
-
294
- ### Theme Customization
295
-
296
- ```typescript
297
- // Component
298
- export class MyComponent {
299
- themeConfig = {
300
- theme: "light",
301
- primaryColor: "#007acc",
302
- backgroundColor: "#ffffff",
303
- toolbarColor: "#f5f5f5",
304
- textColor: "#333333",
305
- borderRadius: "8px",
306
- };
307
- }
308
- ```
309
-
310
- ```html
311
- <!-- Template -->
312
- <ng2-pdfjs-viewer [themeConfig]="themeConfig" [customCSS]="customStyles">
313
- </ng2-pdfjs-viewer>
314
- ```
315
-
316
- ### Custom Loading Spinner
317
-
318
- ```html
319
- <ng-template #customSpinner>
320
- <div class="custom-spinner">
321
- <div class="spinner"></div>
322
- <p>Loading PDF...</p>
323
- </div>
324
- </ng-template>
325
-
326
- <ng2-pdfjs-viewer
327
- [customSpinnerTpl]="customSpinner"
328
- [spinnerClass]="'my-spinner'"
329
- >
330
- </ng2-pdfjs-viewer>
331
- ```
332
-
333
- ### Custom Error Display
334
-
335
- ```html
336
- <ng-template #customError>
337
- <div class="error-container">
338
- <mat-icon>error</mat-icon>
339
- <h3>Failed to Load PDF</h3>
340
- <p>Please check your internet connection and try again.</p>
341
- <button mat-button (click)="retry()">Retry</button>
342
- </div>
343
- </ng-template>
344
-
345
- <ng2-pdfjs-viewer [customErrorTpl]="customError" [errorClass]="'my-error'">
346
- </ng2-pdfjs-viewer>
347
- ```
348
-
349
- ---
350
-
351
- ## 📚 API Reference
352
-
353
- ### Input Properties
354
-
355
- | Property | Type | Default | Description |
356
- | ---------------------------- | ----------------------------------------- | ------------ | ------------------------------------- |
357
- | `pdfSrc` | `string \| Blob \| Uint8Array` | - | PDF source (URL, Blob, or byte array) |
358
- | `viewerId` | `string` | auto | Unique viewer identifier |
359
- | `viewerFolder` | `string` | `'assets'` | Path to PDF.js assets |
360
- | `externalWindow` | `boolean` | `false` | Open in new window |
361
- | `externalWindowOptions` | `string` | - | External window options |
362
- | `target` | `string` | `'_blank'` | Target for external window |
363
- | `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Theme selection |
364
- | `primaryColor` | `string` | `'#007acc'` | Primary color for UI elements |
365
- | `backgroundColor` | `string` | `'#ffffff'` | Background color |
366
- | `pageBorderColor` | `string` | - | Page border color |
367
- | `toolbarColor` | `string` | - | Toolbar background color |
368
- | `textColor` | `string` | - | Text color |
369
- | `borderRadius` | `string` | - | Border radius |
370
- | `customCSS` | `string` | - | Custom CSS styles |
371
- | `showSpinner` | `boolean` | `true` | Show loading spinner |
372
- | `customSpinnerTpl` | `TemplateRef` | - | Custom spinner template |
373
- | `spinnerClass` | `string` | - | Custom spinner CSS class |
374
- | `customErrorTpl` | `TemplateRef` | - | Custom error template |
375
- | `errorClass` | `string` | - | Custom error CSS class |
376
- | `errorOverride` | `boolean` | `false` | Override default error handling |
377
- | `errorAppend` | `boolean` | `true` | Append to default error messages |
378
- | `errorMessage` | `string` | - | Custom error message |
379
- | `locale` | `string` | `'en-US'` | UI language |
380
- | `useOnlyCssZoom` | `boolean` | `false` | Use CSS-based zoom for mobile |
381
- | `diagnosticLogs` | `boolean` | `false` | Enable diagnostic logging |
382
- | `zoom` | `string` | `'auto'` | Initial zoom level (two-way binding) |
383
- | `page` | `number` | `1` | Initial page number |
384
- | `namedDest` | `string` | - | Named destination to navigate to |
385
- | `cursor` | `string` | `'select'` | Cursor type (two-way binding) |
386
- | `scroll` | `string` | `'vertical'` | Scroll mode (two-way binding) |
387
- | `spread` | `string` | `'none'` | Spread mode (two-way binding) |
388
- | `pageMode` | `string` | `'none'` | Page mode (two-way binding) |
389
- | `rotation` | `number` | `0` | Document rotation (two-way binding) |
390
- | `showOpenFile` | `boolean` | `true` | Show open file button |
391
- | `showDownload` | `boolean` | `true` | Show download button |
392
- | `showPrint` | `boolean` | `true` | Show print button |
393
- | `showFind` | `boolean` | `true` | Show search button |
394
- | `showFullScreen` | `boolean` | `true` | Show fullscreen button |
395
- | `showViewBookmark` | `boolean` | `true` | Show bookmark button |
396
- | `showAnnotations` | `boolean` | `false` | Show annotations |
397
- | `showToolbarLeft` | `boolean` | `true` | Show left toolbar section |
398
- | `showToolbarMiddle` | `boolean` | `true` | Show middle toolbar section |
399
- | `showToolbarRight` | `boolean` | `true` | Show right toolbar section |
400
- | `showSecondaryToolbarToggle` | `boolean` | `true` | Show secondary toolbar toggle |
401
- | `showSidebar` | `boolean` | `true` | Show sidebar |
402
- | `showSidebarLeft` | `boolean` | `true` | Show left sidebar |
403
- | `showSidebarRight` | `boolean` | `true` | Show right sidebar |
404
- | `toolbarDensity` | `'compact' \| 'default' \| 'comfortable'` | `'default'` | Toolbar density |
405
- | `sidebarWidth` | `string` | - | Sidebar width (e.g., '280px') |
406
- | `toolbarPosition` | `'top' \| 'bottom'` | `'top'` | Toolbar position |
407
- | `sidebarPosition` | `'left' \| 'right'` | `'left'` | Sidebar position |
408
- | `responsiveBreakpoint` | `string \| number` | - | Responsive breakpoint |
409
- | `downloadOnLoad` | `boolean` | `false` | Auto-download on load |
410
- | `printOnLoad` | `boolean` | `false` | Auto-print on load |
411
- | `rotateCW` | `boolean` | `false` | Rotate clockwise on load |
412
- | `rotateCCW` | `boolean` | `false` | Rotate counter-clockwise on load |
413
- | `showLastPageOnLoad` | `boolean` | `false` | Go to last page on load |
414
- | `downloadFileName` | `string` | - | Custom download filename |
415
- | `controlVisibility` | `ControlVisibilityConfig` | - | Control visibility configuration |
416
- | `autoActions` | `AutoActionConfig` | - | Auto actions configuration |
417
- | `errorHandling` | `ErrorConfig` | - | Error handling configuration |
418
- | `viewerConfig` | `ViewerConfig` | - | Viewer configuration |
419
- | `themeConfig` | `ThemeConfig` | - | Theme configuration |
420
- | `groupVisibility` | `GroupVisibilityConfig` | - | Group visibility configuration |
421
- | `layoutConfig` | `LayoutConfig` | - | Layout configuration |
422
-
423
- ### Output Events
424
-
425
- | Event | Type | Description |
426
- | --------------------------- | ------------------------------------------ | ---------------------------------------------- |
427
- | `onDocumentLoad` | `EventEmitter<void>` | Fired when document loads |
428
- | `onDocumentInit` | `EventEmitter<void>` | Fired when document initializes |
429
- | `onDocumentError` | `EventEmitter<DocumentError>` | Fired when document fails to load |
430
- | `onPageChange` | `EventEmitter<ChangedPage>` | Fired when page changes |
431
- | `onPagesInit` | `EventEmitter<PagesInfo>` | Fired when pages are initialized |
432
- | `onPageRendered` | `EventEmitter<PageRenderInfo>` | Fired when a page is rendered |
433
- | `onScaleChange` | `EventEmitter<ChangedScale>` | Fired when zoom/scale changes |
434
- | `onRotationChange` | `EventEmitter<ChangedRotation>` | Fired when rotation changes |
435
- | `onPresentationModeChanged` | `EventEmitter<PresentationMode>` | Fired when presentation mode changes |
436
- | `onOpenFile` | `EventEmitter<void>` | Fired when open file is clicked |
437
- | `onFind` | `EventEmitter<FindOperation>` | Fired when search is performed |
438
- | `onUpdateFindMatchesCount` | `EventEmitter<FindMatchesCount>` | Fired when search matches are updated |
439
- | `onMetadataLoaded` | `EventEmitter<DocumentMetadata>` | Fired when document metadata loads |
440
- | `onOutlineLoaded` | `EventEmitter<DocumentOutline>` | Fired when document outline loads |
441
- | `onAnnotationLayerRendered` | `EventEmitter<AnnotationLayerRenderEvent>` | Fired when annotation layer renders |
442
- | `onBookmarkClick` | `EventEmitter<BookmarkClick>` | Fired when bookmark is clicked |
443
- | `onIdle` | `EventEmitter<void>` | Fired when viewer becomes idle |
444
- | `onBeforePrint` | `EventEmitter<void>` | Fired before printing |
445
- | `onAfterPrint` | `EventEmitter<void>` | Fired after printing |
446
- | `zoomChange` | `EventEmitter<string>` | Fired when zoom changes (two-way binding) |
447
- | `cursorChange` | `EventEmitter<string>` | Fired when cursor changes (two-way binding) |
448
- | `scrollChange` | `EventEmitter<string>` | Fired when scroll changes (two-way binding) |
449
- | `spreadChange` | `EventEmitter<string>` | Fired when spread changes (two-way binding) |
450
- | `pageModeChange` | `EventEmitter<string>` | Fired when page mode changes (two-way binding) |
451
-
452
- ### Methods
453
-
454
- | Method | Parameters | Returns | Description |
455
- | -------------------------------------------------------- | ----------------------------------------------------------- | ---------------------------------------------------- | --------------------------------- |
456
- | `refresh()` | - | `void` | Refresh viewer |
457
- | `goToPage(page: number)` | `page: number` | `Promise<ActionExecutionResult>` | Navigate to specific page |
458
- | `setPage(page: number)` | `page: number` | `Promise<ActionExecutionResult>` | Set current page |
459
- | `setZoom(zoom: string)` | `zoom: string` | `Promise<ActionExecutionResult>` | Set zoom level |
460
- | `setCursor(cursor: string)` | `cursor: 'select' \| 'hand' \| 'zoom'` | `Promise<ActionExecutionResult>` | Set cursor type |
461
- | `setScroll(scroll: string)` | `scroll: 'vertical' \| 'horizontal' \| 'wrapped' \| 'page'` | `Promise<ActionExecutionResult>` | Set scroll mode |
462
- | `setSpread(spread: string)` | `spread: 'none' \| 'odd' \| 'even'` | `Promise<ActionExecutionResult>` | Set spread mode |
463
- | `setPageMode(mode: string)` | `mode: 'none' \| 'thumbs' \| 'bookmarks' \| 'attachments'` | `Promise<ActionExecutionResult>` | Set page mode |
464
- | `triggerDownload()` | - | `Promise<ActionExecutionResult>` | Trigger download |
465
- | `triggerPrint()` | - | `Promise<ActionExecutionResult>` | Trigger print |
466
- | `triggerRotation(direction: string)` | `direction: 'cw' \| 'ccw'` | `Promise<ActionExecutionResult>` | Rotate document |
467
- | `goToLastPage()` | - | `Promise<ActionExecutionResult>` | Navigate to last page |
468
- | `sendViewerControlMessage(action: string, payload: any)` | `action: string, payload: any` | `Promise<any>` | Send custom control message |
469
- | `getActionStatus(actionId: string)` | `actionId: string` | `Promise<ActionExecutionResult \| null>` | Get action status |
470
- | `getQueueStatus()` | - | `{ queuedActions: number; executedActions: number }` | Get queue status |
471
- | `clearActionQueue()` | - | `void` | Clear action queue |
472
- | `reloadViewer()` | - | `void` | Reload viewer (alias for refresh) |
473
- | `goBack()` | - | `void` | Go back in browser history |
474
- | `closeViewer()` | - | `void` | Close viewer window |
475
- | `getErrorTemplateData()` | - | `any` | Get error template data |
476
-
477
- ---
478
-
479
- ## 🎨 Examples
480
-
481
- ### 1. Basic PDF Viewer
482
-
483
- ```html
484
- <ng2-pdfjs-viewer pdfSrc="assets/sample.pdf" [showSpinner]="true">
485
- </ng2-pdfjs-viewer>
486
- ```
487
-
488
- ### 2. Themed PDF Viewer
489
-
490
- ```html
491
- <ng2-pdfjs-viewer
492
- pdfSrc="assets/sample.pdf"
493
- [theme]="'dark'"
494
- [primaryColor]="'#ff6b6b'"
495
- [backgroundColor]="'#2c3e50'"
496
- >
497
- </ng2-pdfjs-viewer>
498
- ```
499
-
500
- ### 3. Custom Loading & Error
501
-
502
- ```html
503
- <ng-template #loadingTemplate>
504
- <div class="loading">
505
- <mat-spinner></mat-spinner>
506
- <p>Loading your document...</p>
507
- </div>
508
- </ng-template>
509
-
510
- <ng-template #errorTemplate>
511
- <div class="error">
512
- <mat-icon>error_outline</mat-icon>
513
- <h3>Oops! Something went wrong</h3>
514
- <p>We couldn't load your PDF. Please try again.</p>
515
- <button mat-button (click)="retry()">Retry</button>
516
- </div>
517
- </ng-template>
518
-
519
- <ng2-pdfjs-viewer
520
- pdfSrc="assets/sample.pdf"
521
- [customSpinnerTpl]="loadingTemplate"
522
- [customErrorTpl]="errorTemplate"
523
- >
524
- </ng2-pdfjs-viewer>
525
- ```
526
-
527
- ### 4. Programmatic Control
528
-
529
- ```typescript
530
- export class PdfController {
531
- @ViewChild("pdfViewer") pdfViewer!: PdfJsViewerComponent;
532
-
533
- async loadDocument(url: string) {
534
- this.pdfViewer.pdfSrc = url;
535
- await this.pdfViewer.refresh();
536
- }
537
-
538
- async goToPage(page: number) {
539
- await this.pdfViewer.goToPage(page);
540
- }
541
-
542
- async setZoom(zoom: string) {
543
- await this.pdfViewer.setZoom(zoom);
544
- }
545
- }
546
- ```
547
-
548
- ---
549
-
550
- ## 🔄 Migration Guide
551
-
552
- ### From v20.x to v25.x
553
-
554
- #### Breaking Changes
555
-
556
- 1. **PDF.js Upgrade**: Updated to v5.3.93 - some APIs may have changed
557
- 2. **Theme System**: New theme properties replace old styling options
558
- 3. **Error Handling**: Template-based error system replaces HTML strings
559
-
560
- #### Migration Steps
561
-
562
- 1. **Update Dependencies**
563
-
564
- ```bash
565
- npm install ng2-pdfjs-viewer@latest
566
- ```
567
-
568
- 2. **Update Theme Configuration**
569
-
570
- ```typescript
571
- // Old way
572
- [customCSS]="'body { background: red; }'"
573
-
574
- // New way
575
- [theme]="'light'"
576
- [primaryColor]="'#ff0000'"
577
- [backgroundColor]="'#ffffff'"
578
- ```
579
-
580
- 3. **Update Error Handling**
581
-
582
- ```html
583
- <!-- Old way -->
584
- [errorHtml]="'<div>Custom error</div>'"
585
-
586
- <!-- New way -->
587
- <ng-template #errorTemplate>
588
- <div>Custom error</div>
589
- </ng-template>
590
- <ng2-pdfjs-viewer [customErrorTpl]="errorTemplate"></ng2-pdfjs-viewer>
591
- ```
592
-
593
- ---
594
-
595
- ## ⚠️ Deprecated Features
596
-
597
- The following features are deprecated and will be removed in future versions:
598
-
599
- ### Deprecated Properties
600
-
601
- | Deprecated | Replacement | Description |
602
- | ----------------- | -------------------- | --------------------------------------------- |
603
- | `[startDownload]` | `[downloadOnLoad]` | Download document automatically when it opens |
604
- | `[startPrint]` | `[printOnLoad]` | Print document automatically when it opens |
605
- | `[errorHtml]` | `[customErrorTpl]` | Custom error HTML (use template instead) |
606
- | `[errorTemplate]` | `[customErrorTpl]` | Custom error template (renamed) |
607
- | `[spinnerHtml]` | `[customSpinnerTpl]` | Custom spinner HTML (use template instead) |
608
-
609
- ### Deprecated Methods
610
-
611
- | Deprecated | Replacement | Description |
612
- | ------------------ | ------------------------ | ---------------------------------------------- |
613
- | `setErrorHtml()` | Use `[customErrorTpl]` | Set custom error HTML (use template instead) |
614
- | `setSpinnerHtml()` | Use `[customSpinnerTpl]` | Set custom spinner HTML (use template instead) |
615
-
616
- ### Migration Help
617
-
618
- ```typescript
619
- // Deprecated
620
- this.pdfViewer.setErrorHtml("<div>Error</div>");
621
-
622
- // New way
623
- // Use [customErrorTpl] with ng-template
624
- ```
625
-
626
- ---
627
-
628
- ## 📚 Additional Resources
629
-
630
- - **[Custom CSS Examples](Custom-CSS-Examples.md)** - Complete styling guide with theme customization examples
631
- - **[Error Display Examples](Error-Display-Examples.md)** - Custom error template examples and styling options
632
- - **[Contributing Guide](CONTRIBUTING.md)** - How to contribute to the project
633
-
634
- ## 🤝 Contributing
635
-
636
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
637
-
638
- ### Development Setup
639
-
640
- ```bash
641
- # Clone the repository
642
- git clone https://github.com/intbot/ng2-pdfjs-viewer.git
643
-
644
- # Install dependencies
645
- npm install
646
-
647
- # Clear Angular cache (Windows)
648
- Remove-Item -Recurse -Force "SampleApp\.angular"
649
-
650
-
651
- # Build and test - All at once (Windows)
652
- @test.bat
653
- ```
654
-
655
- ### Reporting Issues
656
-
657
- - 🐛 **Bug Reports**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
658
- - 💡 **Feature Requests**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
659
- - 📚 **Documentation**: [GitHub Wiki](https://github.com/intbot/ng2-pdfjs-viewer/wiki)
660
-
661
- ---
662
-
663
- ## 📄 License
664
-
665
- This project is licensed under the **Apache License 2.0 + Commons Clause License Condition v1.0** - see the [LICENSE](LICENSE) file for details.
666
-
667
- ---
668
-
669
- ## 🙏 Acknowledgments
670
-
671
- - **Mozilla PDF.js Team** - For the amazing PDF.js library
672
- - **Angular Team** - For the excellent framework
673
- - **Community Contributors** - For bug reports, feature requests, and contributions
674
- - **7+ Million Users** - For trusting us with your PDF viewing needs
675
-
676
- ---
677
-
678
- ## 📞 Support
679
-
680
- - 📖 **Documentation**: [GitHub Wiki](https://github.com/intbot/ng2-pdfjs-viewer/wiki)
681
- - 💬 **Community**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
682
- - 🐛 **Issues**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
683
- - 📧 **Email**: codehippie1@gmail.com
684
-
685
- ---
686
-
687
- <div align="center">
688
-
689
- **Made with ❤️ by the ng2-pdfjs-viewer team**
690
-
691
- [![GitHub](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/intbot/ng2-pdfjs-viewer)
692
- [![NPM](https://img.shields.io/badge/NPM-Package-red?logo=npm)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
693
- [![Angular](https://img.shields.io/badge/Angular-Component-green?logo=angular)](https://angular.dev/overview)
694
-
695
- </div>
1
+ # Angular PDF viewer powered by Mozilla's PDF.js
2
+
3
+ The most reliable, feature-rich Angular PDF viewer component powered by Mozilla's PDF.js
4
+
5
+ <div align="center">
6
+
7
+ [![NPM Version](https://img.shields.io/npm/v/ng2-pdfjs-viewer?logo=npm&color=blue)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
8
+ [![PDF.js Version](https://img.shields.io/badge/PDF.js%20v5.3.93-latest-green?logo=mozilla)](https://github.com/mozilla/pdf.js)
9
+ [![Angular Support](https://img.shields.io/badge/Angular%2020+-supported-red?logo=angular)](https://angular.dev/overview)
10
+ [![NPM Downloads](https://img.shields.io/npm/dm/ng2-pdfjs-viewer?label=downloads%2Fmonth&color=orange)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
11
+ [![Total Downloads](https://img.shields.io/badge/total%20downloads-7M+-brightgreen?logo=npm)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
12
+ [![Since 2018](https://img.shields.io/badge/since-2018-blue?logo=calendar)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
13
+ [![License](https://img.shields.io/badge/license-Apache%202.0%20%2B%20Commons%20Clause-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
14
+ [![GitHub Stars](https://img.shields.io/github/stars/intbot/ng2-pdfjs-viewer?logo=github)](https://github.com/intbot/ng2-pdfjs-viewer)
15
+
16
+ </div>
17
+
18
+ <div align="center">
19
+
20
+ [**Live Demo**](https://ng2-pdfjs-viewer.azurewebsites.net) • [**API Reference**](#-api-reference) • [**Examples**](#-examples) • [**Migration Guide**](#-migration-guide)
21
+
22
+ </div>
23
+
24
+ ---
25
+
26
+ ng2-pdfjs-viewer is the most comprehensive and feature-rich Angular PDF viewer component available. **Born in 2018** and still going strong with over **7+ million downloads**, this battle-tested library has been trusted by developers worldwide for **over 8 years**, powering thousands of applications.
27
+
28
+ This powerful library enables developers to seamlessly integrate PDF viewing capabilities into Angular applications with enterprise-grade features, custom theming, and mobile-first responsive design. Built on Mozilla's PDF.js v5.3.93, ng2-pdfjs-viewer provides advanced PDF rendering, document navigation, search functionality, and extensive customization options.
29
+
30
+ Whether you need a simple embedded PDF viewer or a complex document management system, this component delivers the performance and flexibility required for modern Angular applications. **The most mature and reliable Angular PDF viewer solution** with continuous updates and long-term support.
31
+
32
+ ### Why Choose ng2-pdfjs-viewer?
33
+
34
+ - **🚀 Always Up-to-Date** - Continuously updated with the latest PDF.js versions and Angular compatibility
35
+ - **🏗️ Enterprise-Ready** - Built for production with comprehensive error handling and performance optimization
36
+ - **🎨 Highly Customizable** - Extensive theming options, custom templates, and flexible configuration
37
+ - **📱 Mobile Optimized** - Touch-friendly interface with responsive design for all screen sizes
38
+ - **🔧 Developer Friendly** - Full TypeScript support, comprehensive documentation, and easy integration
39
+ - **⚡ High Performance** - Event-driven architecture with efficient memory management and lazy loading
40
+ - **🌍 Global Support** - Multi-language support with automatic locale detection and RTL compatibility
41
+ - **🛡️ Production Tested** - Trusted by thousands of applications with millions of downloads
42
+ - **📈 Proven Track Record** - 8+ years of continuous development and community support
43
+ - **🔒 Security Focused** - Regular security updates and vulnerability patches
44
+
45
+ ### 🆕 Latest Features (v25.x)
46
+
47
+ | Feature | Description | Status |
48
+ | ----------------------------- | ------------------------------------------------------------------ | ------ |
49
+ | **Advanced Theme System** | CSS custom properties for complete visual customization | New |
50
+ | **Template-Based UI** | Custom loading spinners and error displays using Angular templates | ✅ New |
51
+ | **Convenience Configuration** | Object-based configuration for cleaner, more maintainable code | ✅ New |
52
+ | **Event-Driven Architecture** | Pure event-based system with universal action dispatcher | ✅ New |
53
+ | **Enhanced Error Handling** | Multiple error display styles with custom templates | ✅ New |
54
+ | **Mobile-First Design** | Responsive layout optimized for touch devices | ✅ New |
55
+ | **TypeScript Strict Mode** | Full type safety with comprehensive API coverage | ✅ New |
56
+
57
+ ### 🏆 Unique Advantages
58
+
59
+ - **Universal Action Dispatcher** - Single pathway for all actions with readiness validation
60
+ - **Template-Based Customization** - Use Angular templates for loading and error states
61
+ - **Comprehensive Event System** - 24+ events covering all user interactions and state changes
62
+ - **Advanced Configuration Objects** - Clean, object-based configuration for complex setups
63
+ - **Production-Ready Architecture** - Event-driven design with no timeouts or polling
64
+ - **Complete API Coverage** - 19+ methods with consistent Promise-based returns
65
+
66
+ ### 🎯 Perfect For
67
+
68
+ - **Enterprise Applications** - Robust, scalable PDF viewing for business applications
69
+ - **Document Management Systems** - Complete PDF handling with search and navigation
70
+ - **E-Learning Platforms** - Interactive PDF viewing for educational content
71
+ - **Financial Applications** - Secure PDF viewing for reports and statements
72
+ - **Healthcare Systems** - Reliable PDF viewing for medical documents
73
+ - **Government Portals** - Accessible PDF viewing for public services
74
+ - **E-Commerce Platforms** - Product catalogs and documentation viewing
75
+ - **Content Management Systems** - Integrated PDF viewing and management
76
+
77
+ ---
78
+
79
+ ## 📋 Table of Contents
80
+
81
+ - [Quick Start](#-quick-start)
82
+ - [Features](#-features)
83
+ - [Installation](#-installation)
84
+ - [Basic Usage](#-basic-usage)
85
+ - [Advanced Configuration](#advanced-configuration)
86
+ - [API Reference](#-api-reference)
87
+ - [Examples](#-examples)
88
+ - [Migration Guide](#-migration-guide)
89
+ - [Deprecated Features](#deprecated-features)
90
+ - [Contributing](#-contributing)
91
+ - [License](#-license)
92
+
93
+ ---
94
+
95
+ ## 🚀 Quick Start
96
+
97
+ ### 1. Install the Package
98
+
99
+ ```bash
100
+ npm install ng2-pdfjs-viewer --save
101
+ ```
102
+
103
+ ### 2. Import the Module
104
+
105
+ ```typescript
106
+ import { NgModule } from "@angular/core";
107
+ import { BrowserModule } from "@angular/platform-browser";
108
+ import { PdfJsViewerModule } from "ng2-pdfjs-viewer";
109
+
110
+ @NgModule({
111
+ imports: [BrowserModule, PdfJsViewerModule],
112
+ // ... rest of your module
113
+ })
114
+ export class AppModule {}
115
+ ```
116
+
117
+ ### 3. Use in Your Component
118
+
119
+ ```html
120
+ <ng2-pdfjs-viewer
121
+ pdfSrc="assets/sample.pdf"
122
+ [showSpinner]="true"
123
+ [theme]="'light'"
124
+ >
125
+ </ng2-pdfjs-viewer>
126
+ ```
127
+
128
+ ### 4. Configure Assets (Required)
129
+
130
+ Add PDF.js assets to your `angular.json`:
131
+
132
+ ```json
133
+ {
134
+ "projects": {
135
+ "your-app": {
136
+ "architect": {
137
+ "build": {
138
+ "options": {
139
+ "assets": [
140
+ {
141
+ "glob": "**/*",
142
+ "input": "node_modules/ng2-pdfjs-viewer/pdfjs",
143
+ "output": "/assets/pdfjs"
144
+ }
145
+ ]
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ ---
155
+
156
+ ## ✨ Features
157
+
158
+ **🎉 7+ Million Downloads & Counting!** - Trusted by developers worldwide for reliable PDF viewing in Angular applications since 2018.
159
+
160
+ ### 🎯 Core PDF Viewing Features
161
+
162
+ - **📄 High-Quality PDF Rendering** - Powered by Mozilla's PDF.js v5.3.93 for superior document display
163
+ - **🔄 Multiple Display Modes** - Embedded viewer, new window, or external tab options
164
+ - **📱 Mobile-First Responsive Design** - Touch-friendly controls optimized for all devices
165
+ - **🌍 Complete Internationalization** - Support for 50+ languages with automatic locale detection
166
+ - **⚡ Optimized Performance** - Lazy loading, memory management, and efficient rendering
167
+
168
+ ### 🎨 Visual Customization
169
+
170
+ - **🎨 Theme System** - Light, dark, and auto themes with custom color schemes
171
+ - **🎭 Custom Styling** - CSS custom properties for complete visual control
172
+ - **🔄 Loading States** - Custom loading spinners with template support
173
+ - **❌ Error Handling** - Multiple error display styles with custom templates
174
+ - **📐 Layout Control** - Toolbar density, sidebar width, and positioning options
175
+
176
+ ### 🔧 Developer Features
177
+
178
+ - **📝 TypeScript Support** - Full type safety with strict mode
179
+ - **🔌 Event System** - Comprehensive event handling for all user interactions
180
+ - **⚙️ Configuration Objects** - Convenience setters for cleaner code
181
+ - **🛠️ API Methods** - Promise-based methods for programmatic control
182
+ - **🐛 Debugging** - Built-in diagnostic logging and error tracking
183
+
184
+ ### 📊 Advanced Features
185
+
186
+ - **🔍 Search & Navigation** - Full-text search with highlighting
187
+ - **📖 Bookmarks & Attachments** - Document structure navigation
188
+ - **🖨️ Print & Download** - Built-in print and download functionality
189
+ - **🔄 Rotation & Zoom** - Document manipulation with smooth animations
190
+ - **📱 Touch Gestures** - Mobile-optimized touch interactions
191
+
192
+ ---
193
+
194
+ ## 📦 Installation
195
+
196
+ ### Prerequisites
197
+
198
+ - **Angular**: 20.0+ (recommended) | 2.0+ (supported)
199
+ - **Node.js**: 18.0+
200
+ - **TypeScript**: 5.0+
201
+
202
+ ### Angular Version Support
203
+
204
+ | Angular Version | Support Level | Notes |
205
+ |----------------|---------------|-------|
206
+ | **20.0+** | ✅ **Recommended** | Fully tested and optimized |
207
+ | **15.0 - 19.x** | ✅ **Supported** | Should work with minor testing |
208
+ | **10.0 - 14.x** | ✅ **Supported** | Compatible with testing |
209
+ | **2.0 - 9.x** | ⚠️ **Legacy** | May require additional testing |
210
+
211
+ **Note**: While the library supports Angular 2.0+, it's primarily tested and optimized for Angular 20+. For production use with older versions, thorough testing is recommended. The library uses relaxed peer dependencies (Angular >=10.0.0) to ensure compatibility across different Angular versions.
212
+
213
+ ### Install Package
214
+
215
+ ```bash
216
+ # Using npm
217
+ npm install ng2-pdfjs-viewer --save
218
+
219
+ # Using yarn
220
+ yarn add ng2-pdfjs-viewer
221
+
222
+ # Using pnpm
223
+ pnpm add ng2-pdfjs-viewer
224
+ ```
225
+
226
+ ### Configure Assets
227
+
228
+ Add PDF.js assets to your `angular.json`:
229
+
230
+ ```json
231
+ {
232
+ "projects": {
233
+ "your-app": {
234
+ "architect": {
235
+ "build": {
236
+ "options": {
237
+ "assets": [
238
+ {
239
+ "glob": "**/*",
240
+ "input": "node_modules/ng2-pdfjs-viewer/pdfjs",
241
+ "output": "/assets/pdfjs"
242
+ }
243
+ ]
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+ ```
251
+
252
+ ---
253
+
254
+ ## 🎯 Basic Usage
255
+
256
+ ### Simple PDF Viewer
257
+
258
+ ```html
259
+ <ng2-pdfjs-viewer pdfSrc="assets/document.pdf" [showSpinner]="true">
260
+ </ng2-pdfjs-viewer>
261
+ ```
262
+
263
+ ### Advanced Configuration
264
+
265
+ ```html
266
+ <ng2-pdfjs-viewer
267
+ pdfSrc="assets/document.pdf"
268
+ [theme]="'dark'"
269
+ [primaryColor]="'#007acc'"
270
+ [showSpinner]="true"
271
+ [customSpinnerTpl]="customSpinner"
272
+ [customErrorTpl]="customError"
273
+ (onDocumentLoad)="onDocumentLoaded($event)"
274
+ (onPageChange)="onPageChanged($event)"
275
+ >
276
+ </ng2-pdfjs-viewer>
277
+ ```
278
+
279
+ ### Programmatic Control
280
+
281
+ ```typescript
282
+ import { Component, ViewChild } from "@angular/core";
283
+ import { PdfJsViewerComponent } from "ng2-pdfjs-viewer";
284
+
285
+ @Component({
286
+ template: `
287
+ <ng2-pdfjs-viewer #pdfViewer pdfSrc="document.pdf"></ng2-pdfjs-viewer>
288
+ <button (click)="goToPage(5)">Go to Page 5</button>
289
+ `,
290
+ })
291
+ export class MyComponent {
292
+ @ViewChild("pdfViewer") pdfViewer!: PdfJsViewerComponent;
293
+
294
+ async goToPage(page: number) {
295
+ await this.pdfViewer.goToPage(page);
296
+ }
297
+ }
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Advanced Configuration
303
+
304
+ ### Theme Customization
305
+
306
+ ```typescript
307
+ // Component
308
+ export class MyComponent {
309
+ themeConfig = {
310
+ theme: "light",
311
+ primaryColor: "#007acc",
312
+ backgroundColor: "#ffffff",
313
+ toolbarColor: "#f5f5f5",
314
+ textColor: "#333333",
315
+ borderRadius: "8px",
316
+ };
317
+ }
318
+ ```
319
+
320
+ ```html
321
+ <!-- Template -->
322
+ <ng2-pdfjs-viewer [themeConfig]="themeConfig" [customCSS]="customStyles">
323
+ </ng2-pdfjs-viewer>
324
+ ```
325
+
326
+ ### Custom Loading Spinner
327
+
328
+ ```html
329
+ <ng-template #customSpinner>
330
+ <div class="custom-spinner">
331
+ <div class="spinner"></div>
332
+ <p>Loading PDF...</p>
333
+ </div>
334
+ </ng-template>
335
+
336
+ <ng2-pdfjs-viewer
337
+ [customSpinnerTpl]="customSpinner"
338
+ [spinnerClass]="'my-spinner'"
339
+ >
340
+ </ng2-pdfjs-viewer>
341
+ ```
342
+
343
+ ### Custom Error Display
344
+
345
+ ```html
346
+ <ng-template #customError>
347
+ <div class="error-container">
348
+ <mat-icon>error</mat-icon>
349
+ <h3>Failed to Load PDF</h3>
350
+ <p>Please check your internet connection and try again.</p>
351
+ <button mat-button (click)="retry()">Retry</button>
352
+ </div>
353
+ </ng-template>
354
+
355
+ <ng2-pdfjs-viewer [customErrorTpl]="customError" [errorClass]="'my-error'">
356
+ </ng2-pdfjs-viewer>
357
+ ```
358
+
359
+ ---
360
+
361
+ ## 📚 API Reference
362
+
363
+ ### Input Properties
364
+
365
+ | Property | Type | Default | Description |
366
+ | ---------------------------- | ----------------------------------------- | ------------ | ------------------------------------- |
367
+ | `pdfSrc` | `string \| Blob \| Uint8Array` | - | PDF source (URL, Blob, or byte array) |
368
+ | `viewerId` | `string` | auto | Unique viewer identifier |
369
+ | `viewerFolder` | `string` | `'assets'` | Path to PDF.js assets |
370
+ | `externalWindow` | `boolean` | `false` | Open in new window |
371
+ | `externalWindowOptions` | `string` | - | External window options |
372
+ | `target` | `string` | `'_blank'` | Target for external window |
373
+ | `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Theme selection |
374
+ | `primaryColor` | `string` | `'#007acc'` | Primary color for UI elements |
375
+ | `backgroundColor` | `string` | `'#ffffff'` | Background color |
376
+ | `pageBorderColor` | `string` | - | Page border color |
377
+ | `toolbarColor` | `string` | - | Toolbar background color |
378
+ | `textColor` | `string` | - | Text color |
379
+ | `borderRadius` | `string` | - | Border radius |
380
+ | `customCSS` | `string` | - | Custom CSS styles |
381
+ | `showSpinner` | `boolean` | `true` | Show loading spinner |
382
+ | `customSpinnerTpl` | `TemplateRef` | - | Custom spinner template |
383
+ | `spinnerClass` | `string` | - | Custom spinner CSS class |
384
+ | `customErrorTpl` | `TemplateRef` | - | Custom error template |
385
+ | `errorClass` | `string` | - | Custom error CSS class |
386
+ | `errorOverride` | `boolean` | `false` | Override default error handling |
387
+ | `errorAppend` | `boolean` | `true` | Append to default error messages |
388
+ | `errorMessage` | `string` | - | Custom error message |
389
+ | `locale` | `string` | `'en-US'` | UI language |
390
+ | `useOnlyCssZoom` | `boolean` | `false` | Use CSS-based zoom for mobile |
391
+ | `diagnosticLogs` | `boolean` | `false` | Enable diagnostic logging |
392
+ | `zoom` | `string` | `'auto'` | Initial zoom level (two-way binding) |
393
+ | `page` | `number` | `1` | Initial page number |
394
+ | `namedDest` | `string` | - | Named destination to navigate to |
395
+ | `cursor` | `string` | `'select'` | Cursor type (two-way binding) |
396
+ | `scroll` | `string` | `'vertical'` | Scroll mode (two-way binding) |
397
+ | `spread` | `string` | `'none'` | Spread mode (two-way binding) |
398
+ | `pageMode` | `string` | `'none'` | Page mode (two-way binding) |
399
+ | `rotation` | `number` | `0` | Document rotation (two-way binding) |
400
+ | `showOpenFile` | `boolean` | `true` | Show open file button |
401
+ | `showDownload` | `boolean` | `true` | Show download button |
402
+ | `showPrint` | `boolean` | `true` | Show print button |
403
+ | `showFind` | `boolean` | `true` | Show search button |
404
+ | `showFullScreen` | `boolean` | `true` | Show fullscreen button |
405
+ | `showViewBookmark` | `boolean` | `true` | Show bookmark button |
406
+ | `showAnnotations` | `boolean` | `false` | Show annotations |
407
+ | `showToolbarLeft` | `boolean` | `true` | Show left toolbar section |
408
+ | `showToolbarMiddle` | `boolean` | `true` | Show middle toolbar section |
409
+ | `showToolbarRight` | `boolean` | `true` | Show right toolbar section |
410
+ | `showSecondaryToolbarToggle` | `boolean` | `true` | Show secondary toolbar toggle |
411
+ | `showSidebar` | `boolean` | `true` | Show sidebar |
412
+ | `showSidebarLeft` | `boolean` | `true` | Show left sidebar |
413
+ | `showSidebarRight` | `boolean` | `true` | Show right sidebar |
414
+ | `toolbarDensity` | `'compact' \| 'default' \| 'comfortable'` | `'default'` | Toolbar density |
415
+ | `sidebarWidth` | `string` | - | Sidebar width (e.g., '280px') |
416
+ | `toolbarPosition` | `'top' \| 'bottom'` | `'top'` | Toolbar position |
417
+ | `sidebarPosition` | `'left' \| 'right'` | `'left'` | Sidebar position |
418
+ | `responsiveBreakpoint` | `string \| number` | - | Responsive breakpoint |
419
+ | `downloadOnLoad` | `boolean` | `false` | Auto-download on load |
420
+ | `printOnLoad` | `boolean` | `false` | Auto-print on load |
421
+ | `rotateCW` | `boolean` | `false` | Rotate clockwise on load |
422
+ | `rotateCCW` | `boolean` | `false` | Rotate counter-clockwise on load |
423
+ | `showLastPageOnLoad` | `boolean` | `false` | Go to last page on load |
424
+ | `downloadFileName` | `string` | - | Custom download filename |
425
+ | `controlVisibility` | `ControlVisibilityConfig` | - | Control visibility configuration |
426
+ | `autoActions` | `AutoActionConfig` | - | Auto actions configuration |
427
+ | `errorHandling` | `ErrorConfig` | - | Error handling configuration |
428
+ | `viewerConfig` | `ViewerConfig` | - | Viewer configuration |
429
+ | `themeConfig` | `ThemeConfig` | - | Theme configuration |
430
+ | `groupVisibility` | `GroupVisibilityConfig` | - | Group visibility configuration |
431
+ | `layoutConfig` | `LayoutConfig` | - | Layout configuration |
432
+
433
+ ### Output Events
434
+
435
+ | Event | Type | Description |
436
+ | --------------------------- | ------------------------------------------ | ---------------------------------------------- |
437
+ | `onDocumentLoad` | `EventEmitter<void>` | Fired when document loads |
438
+ | `onDocumentInit` | `EventEmitter<void>` | Fired when document initializes |
439
+ | `onDocumentError` | `EventEmitter<DocumentError>` | Fired when document fails to load |
440
+ | `onPageChange` | `EventEmitter<ChangedPage>` | Fired when page changes |
441
+ | `onPagesInit` | `EventEmitter<PagesInfo>` | Fired when pages are initialized |
442
+ | `onPageRendered` | `EventEmitter<PageRenderInfo>` | Fired when a page is rendered |
443
+ | `onScaleChange` | `EventEmitter<ChangedScale>` | Fired when zoom/scale changes |
444
+ | `onRotationChange` | `EventEmitter<ChangedRotation>` | Fired when rotation changes |
445
+ | `onPresentationModeChanged` | `EventEmitter<PresentationMode>` | Fired when presentation mode changes |
446
+ | `onOpenFile` | `EventEmitter<void>` | Fired when open file is clicked |
447
+ | `onFind` | `EventEmitter<FindOperation>` | Fired when search is performed |
448
+ | `onUpdateFindMatchesCount` | `EventEmitter<FindMatchesCount>` | Fired when search matches are updated |
449
+ | `onMetadataLoaded` | `EventEmitter<DocumentMetadata>` | Fired when document metadata loads |
450
+ | `onOutlineLoaded` | `EventEmitter<DocumentOutline>` | Fired when document outline loads |
451
+ | `onAnnotationLayerRendered` | `EventEmitter<AnnotationLayerRenderEvent>` | Fired when annotation layer renders |
452
+ | `onBookmarkClick` | `EventEmitter<BookmarkClick>` | Fired when bookmark is clicked |
453
+ | `onIdle` | `EventEmitter<void>` | Fired when viewer becomes idle |
454
+ | `onBeforePrint` | `EventEmitter<void>` | Fired before printing |
455
+ | `onAfterPrint` | `EventEmitter<void>` | Fired after printing |
456
+ | `zoomChange` | `EventEmitter<string>` | Fired when zoom changes (two-way binding) |
457
+ | `cursorChange` | `EventEmitter<string>` | Fired when cursor changes (two-way binding) |
458
+ | `scrollChange` | `EventEmitter<string>` | Fired when scroll changes (two-way binding) |
459
+ | `spreadChange` | `EventEmitter<string>` | Fired when spread changes (two-way binding) |
460
+ | `pageModeChange` | `EventEmitter<string>` | Fired when page mode changes (two-way binding) |
461
+
462
+ ### Methods
463
+
464
+ | Method | Parameters | Returns | Description |
465
+ | -------------------------------------------------------- | ----------------------------------------------------------- | ---------------------------------------------------- | --------------------------------- |
466
+ | `refresh()` | - | `void` | Refresh viewer |
467
+ | `goToPage(page: number)` | `page: number` | `Promise<ActionExecutionResult>` | Navigate to specific page |
468
+ | `setPage(page: number)` | `page: number` | `Promise<ActionExecutionResult>` | Set current page |
469
+ | `setZoom(zoom: string)` | `zoom: string` | `Promise<ActionExecutionResult>` | Set zoom level |
470
+ | `setCursor(cursor: string)` | `cursor: 'select' \| 'hand' \| 'zoom'` | `Promise<ActionExecutionResult>` | Set cursor type |
471
+ | `setScroll(scroll: string)` | `scroll: 'vertical' \| 'horizontal' \| 'wrapped' \| 'page'` | `Promise<ActionExecutionResult>` | Set scroll mode |
472
+ | `setSpread(spread: string)` | `spread: 'none' \| 'odd' \| 'even'` | `Promise<ActionExecutionResult>` | Set spread mode |
473
+ | `setPageMode(mode: string)` | `mode: 'none' \| 'thumbs' \| 'bookmarks' \| 'attachments'` | `Promise<ActionExecutionResult>` | Set page mode |
474
+ | `triggerDownload()` | - | `Promise<ActionExecutionResult>` | Trigger download |
475
+ | `triggerPrint()` | - | `Promise<ActionExecutionResult>` | Trigger print |
476
+ | `triggerRotation(direction: string)` | `direction: 'cw' \| 'ccw'` | `Promise<ActionExecutionResult>` | Rotate document |
477
+ | `goToLastPage()` | - | `Promise<ActionExecutionResult>` | Navigate to last page |
478
+ | `sendViewerControlMessage(action: string, payload: any)` | `action: string, payload: any` | `Promise<any>` | Send custom control message |
479
+ | `getActionStatus(actionId: string)` | `actionId: string` | `Promise<ActionExecutionResult \| null>` | Get action status |
480
+ | `getQueueStatus()` | - | `{ queuedActions: number; executedActions: number }` | Get queue status |
481
+ | `clearActionQueue()` | - | `void` | Clear action queue |
482
+ | `reloadViewer()` | - | `void` | Reload viewer (alias for refresh) |
483
+ | `goBack()` | - | `void` | Go back in browser history |
484
+ | `closeViewer()` | - | `void` | Close viewer window |
485
+ | `getErrorTemplateData()` | - | `any` | Get error template data |
486
+
487
+ ---
488
+
489
+ ## 🎨 Examples
490
+
491
+ ### 1. Basic PDF Viewer
492
+
493
+ ```html
494
+ <ng2-pdfjs-viewer pdfSrc="assets/sample.pdf" [showSpinner]="true">
495
+ </ng2-pdfjs-viewer>
496
+ ```
497
+
498
+ ### 2. Themed PDF Viewer
499
+
500
+ ```html
501
+ <ng2-pdfjs-viewer
502
+ pdfSrc="assets/sample.pdf"
503
+ [theme]="'dark'"
504
+ [primaryColor]="'#ff6b6b'"
505
+ [backgroundColor]="'#2c3e50'"
506
+ >
507
+ </ng2-pdfjs-viewer>
508
+ ```
509
+
510
+ ### 3. Custom Loading & Error
511
+
512
+ ```html
513
+ <ng-template #loadingTemplate>
514
+ <div class="loading">
515
+ <mat-spinner></mat-spinner>
516
+ <p>Loading your document...</p>
517
+ </div>
518
+ </ng-template>
519
+
520
+ <ng-template #errorTemplate>
521
+ <div class="error">
522
+ <mat-icon>error_outline</mat-icon>
523
+ <h3>Oops! Something went wrong</h3>
524
+ <p>We couldn't load your PDF. Please try again.</p>
525
+ <button mat-button (click)="retry()">Retry</button>
526
+ </div>
527
+ </ng-template>
528
+
529
+ <ng2-pdfjs-viewer
530
+ pdfSrc="assets/sample.pdf"
531
+ [customSpinnerTpl]="loadingTemplate"
532
+ [customErrorTpl]="errorTemplate"
533
+ >
534
+ </ng2-pdfjs-viewer>
535
+ ```
536
+
537
+ ### 4. Programmatic Control
538
+
539
+ ```typescript
540
+ export class PdfController {
541
+ @ViewChild("pdfViewer") pdfViewer!: PdfJsViewerComponent;
542
+
543
+ async loadDocument(url: string) {
544
+ this.pdfViewer.pdfSrc = url;
545
+ await this.pdfViewer.refresh();
546
+ }
547
+
548
+ async goToPage(page: number) {
549
+ await this.pdfViewer.goToPage(page);
550
+ }
551
+
552
+ async setZoom(zoom: string) {
553
+ await this.pdfViewer.setZoom(zoom);
554
+ }
555
+ }
556
+ ```
557
+
558
+ ---
559
+
560
+ ## 🔄 Migration Guide
561
+
562
+ ### From v20.x to v25.x
563
+
564
+ #### Breaking Changes
565
+
566
+ 1. **PDF.js Upgrade**: Updated to v5.3.93 - some APIs may have changed
567
+ 2. **Theme System**: New theme properties replace old styling options
568
+ 3. **Error Handling**: Template-based error system replaces HTML strings
569
+
570
+ #### Migration Steps
571
+
572
+ 1. **Update Dependencies**
573
+
574
+ ```bash
575
+ npm install ng2-pdfjs-viewer@latest
576
+ ```
577
+
578
+ 2. **Update Theme Configuration**
579
+
580
+ ```typescript
581
+ // Old way
582
+ [customCSS]="'body { background: red; }'"
583
+
584
+ // New way
585
+ [theme]="'light'"
586
+ [primaryColor]="'#ff0000'"
587
+ [backgroundColor]="'#ffffff'"
588
+ ```
589
+
590
+ 3. **Update Error Handling**
591
+
592
+ ```html
593
+ <!-- Old way -->
594
+ [errorHtml]="'<div>Custom error</div>'"
595
+
596
+ <!-- New way -->
597
+ <ng-template #errorTemplate>
598
+ <div>Custom error</div>
599
+ </ng-template>
600
+ <ng2-pdfjs-viewer [customErrorTpl]="errorTemplate"></ng2-pdfjs-viewer>
601
+ ```
602
+
603
+ 4. **Update Spinner Handling**
604
+
605
+ ```html
606
+ <!-- Old way -->
607
+ [spinnerHtml]="'<div class=\"spinner\">Loading...</div>'"
608
+
609
+ <!-- New way -->
610
+ <ng-template #spinnerTemplate>
611
+ <div class="spinner">Loading...</div>
612
+ </ng-template>
613
+ <ng2-pdfjs-viewer [customSpinnerTpl]="spinnerTemplate"></ng2-pdfjs-viewer>
614
+ ```
615
+
616
+ ```typescript
617
+ // Old way
618
+ this.pdfViewer.setSpinnerHtml('<div>Loading...</div>');
619
+
620
+ // New way
621
+ // Use [customSpinnerTpl] with ng-template
622
+ ```
623
+
624
+ ---
625
+
626
+ ## Deprecated Features
627
+
628
+ The following features are deprecated and will be removed in future versions:
629
+
630
+ ### Deprecated Properties
631
+
632
+ | Deprecated | Replacement | Description |
633
+ | ----------------- | -------------------- | --------------------------------------------- |
634
+ | `[startDownload]` | `[downloadOnLoad]` | Download document automatically when it opens |
635
+ | `[startPrint]` | `[printOnLoad]` | Print document automatically when it opens |
636
+ | `[errorHtml]` | `[customErrorTpl]` | Custom error HTML (use template instead) |
637
+ | `[errorTemplate]` | `[customErrorTpl]` | Custom error template (renamed) |
638
+ | `[spinnerHtml]` | `[customSpinnerTpl]` | Custom spinner HTML (use template instead) |
639
+
640
+ ### Deprecated Methods
641
+
642
+ | Deprecated | Replacement | Description |
643
+ | ------------------ | ------------------------ | ---------------------------------------------- |
644
+ | `setErrorHtml()` | Use `[customErrorTpl]` | Set custom error HTML (use template instead) |
645
+ | `setSpinnerHtml()` | Use `[customSpinnerTpl]` | Set custom spinner HTML (use template instead) |
646
+
647
+ ### Migration Help
648
+
649
+ ```typescript
650
+ // Deprecated - Error Handling
651
+ this.pdfViewer.setErrorHtml("<div>Error</div>");
652
+
653
+ // New way - Error Handling
654
+ // Use [customErrorTpl] with ng-template
655
+
656
+ // Deprecated - Spinner Handling
657
+ this.pdfViewer.setSpinnerHtml("<div>Loading...</div>");
658
+
659
+ // New way - Spinner Handling
660
+ // Use [customSpinnerTpl] with ng-template
661
+ ```
662
+
663
+ ---
664
+
665
+ ## 📚 Additional Resources
666
+
667
+ - **[Custom CSS Examples](Custom-CSS-Examples.md)** - Complete styling guide with theme customization examples
668
+ - **[Error Display Examples](Error-Display-Examples.md)** - Custom error template examples and styling options
669
+ - **[Contributing Guide](CONTRIBUTING.md)** - How to contribute to the project
670
+
671
+ ## 🤝 Contributing
672
+
673
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
674
+
675
+ ### Development Setup
676
+
677
+ ```bash
678
+ # Clone the repository
679
+ git clone https://github.com/intbot/ng2-pdfjs-viewer.git
680
+
681
+ # Install dependencies
682
+ npm install
683
+
684
+ # Clear Angular cache (Windows)
685
+ Remove-Item -Recurse -Force "SampleApp\.angular"
686
+
687
+
688
+ # Build and test - All at once (Windows)
689
+ @test.bat
690
+ ```
691
+
692
+ ### Reporting Issues
693
+
694
+ - 🐛 **Bug Reports**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
695
+ - 💡 **Feature Requests**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
696
+ - 📚 **Documentation**: [GitHub Wiki](https://github.com/intbot/ng2-pdfjs-viewer/wiki)
697
+
698
+ ---
699
+
700
+ ## 📄 License
701
+
702
+ This project is licensed under the **Apache License 2.0 + Commons Clause License Condition v1.0** - see the [LICENSE](LICENSE) file for details.
703
+
704
+ ---
705
+
706
+ ## 🙏 Acknowledgments
707
+
708
+ - **Mozilla PDF.js Team** - For the amazing PDF.js library
709
+ - **Angular Team** - For the excellent framework
710
+ - **Community Contributors** - For bug reports, feature requests, and contributions
711
+ - **7+ Million Users** - For trusting us with your PDF viewing needs
712
+
713
+ ---
714
+
715
+ ## 📞 Support
716
+
717
+ - 📖 **Documentation**: [GitHub Wiki](https://github.com/intbot/ng2-pdfjs-viewer/wiki)
718
+ - 💬 **Community**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
719
+ - 🐛 **Issues**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
720
+ - 📧 **Email**: codehippie1@gmail.com
721
+
722
+ ---
723
+
724
+ <div align="center">
725
+
726
+ **Made with ❤️ by [Aneesh](http://github.com/codehippie1)**
727
+
728
+ [![GitHub](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/intbot/ng2-pdfjs-viewer)
729
+ [![NPM](https://img.shields.io/badge/NPM-Package-red?logo=npm)](https://www.npmjs.com/package/ng2-pdfjs-viewer)
730
+ [![Angular](https://img.shields.io/badge/Angular-Component-green?logo=angular)](https://angular.dev/overview)
731
+
732
+ </div>