ng2-pdfjs-viewer 25.0.0 → 25.0.3
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 +721 -0
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,721 @@
|
|
|
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
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
8
|
+
[](https://github.com/mozilla/pdf.js)
|
|
9
|
+
[](https://angular.dev/overview)
|
|
10
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
11
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
12
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
13
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
14
|
+
[](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+ (supports Angular 2.0+)
|
|
199
|
+
- Node.js 18.0+
|
|
200
|
+
- TypeScript 5.0+
|
|
201
|
+
|
|
202
|
+
### Install Package
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Using npm
|
|
206
|
+
npm install ng2-pdfjs-viewer --save
|
|
207
|
+
|
|
208
|
+
# Using yarn
|
|
209
|
+
yarn add ng2-pdfjs-viewer
|
|
210
|
+
|
|
211
|
+
# Using pnpm
|
|
212
|
+
pnpm add ng2-pdfjs-viewer
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Configure Assets
|
|
216
|
+
|
|
217
|
+
Add PDF.js assets to your `angular.json`:
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"projects": {
|
|
222
|
+
"your-app": {
|
|
223
|
+
"architect": {
|
|
224
|
+
"build": {
|
|
225
|
+
"options": {
|
|
226
|
+
"assets": [
|
|
227
|
+
{
|
|
228
|
+
"glob": "**/*",
|
|
229
|
+
"input": "node_modules/ng2-pdfjs-viewer/pdfjs",
|
|
230
|
+
"output": "/assets/pdfjs"
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## 🎯 Basic Usage
|
|
244
|
+
|
|
245
|
+
### Simple PDF Viewer
|
|
246
|
+
|
|
247
|
+
```html
|
|
248
|
+
<ng2-pdfjs-viewer pdfSrc="assets/document.pdf" [showSpinner]="true">
|
|
249
|
+
</ng2-pdfjs-viewer>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Advanced Configuration
|
|
253
|
+
|
|
254
|
+
```html
|
|
255
|
+
<ng2-pdfjs-viewer
|
|
256
|
+
pdfSrc="assets/document.pdf"
|
|
257
|
+
[theme]="'dark'"
|
|
258
|
+
[primaryColor]="'#007acc'"
|
|
259
|
+
[showSpinner]="true"
|
|
260
|
+
[customSpinnerTpl]="customSpinner"
|
|
261
|
+
[customErrorTpl]="customError"
|
|
262
|
+
(onDocumentLoad)="onDocumentLoaded($event)"
|
|
263
|
+
(onPageChange)="onPageChanged($event)"
|
|
264
|
+
>
|
|
265
|
+
</ng2-pdfjs-viewer>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Programmatic Control
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { Component, ViewChild } from "@angular/core";
|
|
272
|
+
import { PdfJsViewerComponent } from "ng2-pdfjs-viewer";
|
|
273
|
+
|
|
274
|
+
@Component({
|
|
275
|
+
template: `
|
|
276
|
+
<ng2-pdfjs-viewer #pdfViewer pdfSrc="document.pdf"></ng2-pdfjs-viewer>
|
|
277
|
+
<button (click)="goToPage(5)">Go to Page 5</button>
|
|
278
|
+
`,
|
|
279
|
+
})
|
|
280
|
+
export class MyComponent {
|
|
281
|
+
@ViewChild("pdfViewer") pdfViewer!: PdfJsViewerComponent;
|
|
282
|
+
|
|
283
|
+
async goToPage(page: number) {
|
|
284
|
+
await this.pdfViewer.goToPage(page);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Advanced Configuration
|
|
292
|
+
|
|
293
|
+
### Theme Customization
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
// Component
|
|
297
|
+
export class MyComponent {
|
|
298
|
+
themeConfig = {
|
|
299
|
+
theme: "light",
|
|
300
|
+
primaryColor: "#007acc",
|
|
301
|
+
backgroundColor: "#ffffff",
|
|
302
|
+
toolbarColor: "#f5f5f5",
|
|
303
|
+
textColor: "#333333",
|
|
304
|
+
borderRadius: "8px",
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
```html
|
|
310
|
+
<!-- Template -->
|
|
311
|
+
<ng2-pdfjs-viewer [themeConfig]="themeConfig" [customCSS]="customStyles">
|
|
312
|
+
</ng2-pdfjs-viewer>
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Custom Loading Spinner
|
|
316
|
+
|
|
317
|
+
```html
|
|
318
|
+
<ng-template #customSpinner>
|
|
319
|
+
<div class="custom-spinner">
|
|
320
|
+
<div class="spinner"></div>
|
|
321
|
+
<p>Loading PDF...</p>
|
|
322
|
+
</div>
|
|
323
|
+
</ng-template>
|
|
324
|
+
|
|
325
|
+
<ng2-pdfjs-viewer
|
|
326
|
+
[customSpinnerTpl]="customSpinner"
|
|
327
|
+
[spinnerClass]="'my-spinner'"
|
|
328
|
+
>
|
|
329
|
+
</ng2-pdfjs-viewer>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Custom Error Display
|
|
333
|
+
|
|
334
|
+
```html
|
|
335
|
+
<ng-template #customError>
|
|
336
|
+
<div class="error-container">
|
|
337
|
+
<mat-icon>error</mat-icon>
|
|
338
|
+
<h3>Failed to Load PDF</h3>
|
|
339
|
+
<p>Please check your internet connection and try again.</p>
|
|
340
|
+
<button mat-button (click)="retry()">Retry</button>
|
|
341
|
+
</div>
|
|
342
|
+
</ng-template>
|
|
343
|
+
|
|
344
|
+
<ng2-pdfjs-viewer [customErrorTpl]="customError" [errorClass]="'my-error'">
|
|
345
|
+
</ng2-pdfjs-viewer>
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## 📚 API Reference
|
|
351
|
+
|
|
352
|
+
### Input Properties
|
|
353
|
+
|
|
354
|
+
| Property | Type | Default | Description |
|
|
355
|
+
| ---------------------------- | ----------------------------------------- | ------------ | ------------------------------------- |
|
|
356
|
+
| `pdfSrc` | `string \| Blob \| Uint8Array` | - | PDF source (URL, Blob, or byte array) |
|
|
357
|
+
| `viewerId` | `string` | auto | Unique viewer identifier |
|
|
358
|
+
| `viewerFolder` | `string` | `'assets'` | Path to PDF.js assets |
|
|
359
|
+
| `externalWindow` | `boolean` | `false` | Open in new window |
|
|
360
|
+
| `externalWindowOptions` | `string` | - | External window options |
|
|
361
|
+
| `target` | `string` | `'_blank'` | Target for external window |
|
|
362
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Theme selection |
|
|
363
|
+
| `primaryColor` | `string` | `'#007acc'` | Primary color for UI elements |
|
|
364
|
+
| `backgroundColor` | `string` | `'#ffffff'` | Background color |
|
|
365
|
+
| `pageBorderColor` | `string` | - | Page border color |
|
|
366
|
+
| `toolbarColor` | `string` | - | Toolbar background color |
|
|
367
|
+
| `textColor` | `string` | - | Text color |
|
|
368
|
+
| `borderRadius` | `string` | - | Border radius |
|
|
369
|
+
| `customCSS` | `string` | - | Custom CSS styles |
|
|
370
|
+
| `showSpinner` | `boolean` | `true` | Show loading spinner |
|
|
371
|
+
| `customSpinnerTpl` | `TemplateRef` | - | Custom spinner template |
|
|
372
|
+
| `spinnerClass` | `string` | - | Custom spinner CSS class |
|
|
373
|
+
| `customErrorTpl` | `TemplateRef` | - | Custom error template |
|
|
374
|
+
| `errorClass` | `string` | - | Custom error CSS class |
|
|
375
|
+
| `errorOverride` | `boolean` | `false` | Override default error handling |
|
|
376
|
+
| `errorAppend` | `boolean` | `true` | Append to default error messages |
|
|
377
|
+
| `errorMessage` | `string` | - | Custom error message |
|
|
378
|
+
| `locale` | `string` | `'en-US'` | UI language |
|
|
379
|
+
| `useOnlyCssZoom` | `boolean` | `false` | Use CSS-based zoom for mobile |
|
|
380
|
+
| `diagnosticLogs` | `boolean` | `false` | Enable diagnostic logging |
|
|
381
|
+
| `zoom` | `string` | `'auto'` | Initial zoom level (two-way binding) |
|
|
382
|
+
| `page` | `number` | `1` | Initial page number |
|
|
383
|
+
| `namedDest` | `string` | - | Named destination to navigate to |
|
|
384
|
+
| `cursor` | `string` | `'select'` | Cursor type (two-way binding) |
|
|
385
|
+
| `scroll` | `string` | `'vertical'` | Scroll mode (two-way binding) |
|
|
386
|
+
| `spread` | `string` | `'none'` | Spread mode (two-way binding) |
|
|
387
|
+
| `pageMode` | `string` | `'none'` | Page mode (two-way binding) |
|
|
388
|
+
| `rotation` | `number` | `0` | Document rotation (two-way binding) |
|
|
389
|
+
| `showOpenFile` | `boolean` | `true` | Show open file button |
|
|
390
|
+
| `showDownload` | `boolean` | `true` | Show download button |
|
|
391
|
+
| `showPrint` | `boolean` | `true` | Show print button |
|
|
392
|
+
| `showFind` | `boolean` | `true` | Show search button |
|
|
393
|
+
| `showFullScreen` | `boolean` | `true` | Show fullscreen button |
|
|
394
|
+
| `showViewBookmark` | `boolean` | `true` | Show bookmark button |
|
|
395
|
+
| `showAnnotations` | `boolean` | `false` | Show annotations |
|
|
396
|
+
| `showToolbarLeft` | `boolean` | `true` | Show left toolbar section |
|
|
397
|
+
| `showToolbarMiddle` | `boolean` | `true` | Show middle toolbar section |
|
|
398
|
+
| `showToolbarRight` | `boolean` | `true` | Show right toolbar section |
|
|
399
|
+
| `showSecondaryToolbarToggle` | `boolean` | `true` | Show secondary toolbar toggle |
|
|
400
|
+
| `showSidebar` | `boolean` | `true` | Show sidebar |
|
|
401
|
+
| `showSidebarLeft` | `boolean` | `true` | Show left sidebar |
|
|
402
|
+
| `showSidebarRight` | `boolean` | `true` | Show right sidebar |
|
|
403
|
+
| `toolbarDensity` | `'compact' \| 'default' \| 'comfortable'` | `'default'` | Toolbar density |
|
|
404
|
+
| `sidebarWidth` | `string` | - | Sidebar width (e.g., '280px') |
|
|
405
|
+
| `toolbarPosition` | `'top' \| 'bottom'` | `'top'` | Toolbar position |
|
|
406
|
+
| `sidebarPosition` | `'left' \| 'right'` | `'left'` | Sidebar position |
|
|
407
|
+
| `responsiveBreakpoint` | `string \| number` | - | Responsive breakpoint |
|
|
408
|
+
| `downloadOnLoad` | `boolean` | `false` | Auto-download on load |
|
|
409
|
+
| `printOnLoad` | `boolean` | `false` | Auto-print on load |
|
|
410
|
+
| `rotateCW` | `boolean` | `false` | Rotate clockwise on load |
|
|
411
|
+
| `rotateCCW` | `boolean` | `false` | Rotate counter-clockwise on load |
|
|
412
|
+
| `showLastPageOnLoad` | `boolean` | `false` | Go to last page on load |
|
|
413
|
+
| `downloadFileName` | `string` | - | Custom download filename |
|
|
414
|
+
| `controlVisibility` | `ControlVisibilityConfig` | - | Control visibility configuration |
|
|
415
|
+
| `autoActions` | `AutoActionConfig` | - | Auto actions configuration |
|
|
416
|
+
| `errorHandling` | `ErrorConfig` | - | Error handling configuration |
|
|
417
|
+
| `viewerConfig` | `ViewerConfig` | - | Viewer configuration |
|
|
418
|
+
| `themeConfig` | `ThemeConfig` | - | Theme configuration |
|
|
419
|
+
| `groupVisibility` | `GroupVisibilityConfig` | - | Group visibility configuration |
|
|
420
|
+
| `layoutConfig` | `LayoutConfig` | - | Layout configuration |
|
|
421
|
+
|
|
422
|
+
### Output Events
|
|
423
|
+
|
|
424
|
+
| Event | Type | Description |
|
|
425
|
+
| --------------------------- | ------------------------------------------ | ---------------------------------------------- |
|
|
426
|
+
| `onDocumentLoad` | `EventEmitter<void>` | Fired when document loads |
|
|
427
|
+
| `onDocumentInit` | `EventEmitter<void>` | Fired when document initializes |
|
|
428
|
+
| `onDocumentError` | `EventEmitter<DocumentError>` | Fired when document fails to load |
|
|
429
|
+
| `onPageChange` | `EventEmitter<ChangedPage>` | Fired when page changes |
|
|
430
|
+
| `onPagesInit` | `EventEmitter<PagesInfo>` | Fired when pages are initialized |
|
|
431
|
+
| `onPageRendered` | `EventEmitter<PageRenderInfo>` | Fired when a page is rendered |
|
|
432
|
+
| `onScaleChange` | `EventEmitter<ChangedScale>` | Fired when zoom/scale changes |
|
|
433
|
+
| `onRotationChange` | `EventEmitter<ChangedRotation>` | Fired when rotation changes |
|
|
434
|
+
| `onPresentationModeChanged` | `EventEmitter<PresentationMode>` | Fired when presentation mode changes |
|
|
435
|
+
| `onOpenFile` | `EventEmitter<void>` | Fired when open file is clicked |
|
|
436
|
+
| `onFind` | `EventEmitter<FindOperation>` | Fired when search is performed |
|
|
437
|
+
| `onUpdateFindMatchesCount` | `EventEmitter<FindMatchesCount>` | Fired when search matches are updated |
|
|
438
|
+
| `onMetadataLoaded` | `EventEmitter<DocumentMetadata>` | Fired when document metadata loads |
|
|
439
|
+
| `onOutlineLoaded` | `EventEmitter<DocumentOutline>` | Fired when document outline loads |
|
|
440
|
+
| `onAnnotationLayerRendered` | `EventEmitter<AnnotationLayerRenderEvent>` | Fired when annotation layer renders |
|
|
441
|
+
| `onBookmarkClick` | `EventEmitter<BookmarkClick>` | Fired when bookmark is clicked |
|
|
442
|
+
| `onIdle` | `EventEmitter<void>` | Fired when viewer becomes idle |
|
|
443
|
+
| `onBeforePrint` | `EventEmitter<void>` | Fired before printing |
|
|
444
|
+
| `onAfterPrint` | `EventEmitter<void>` | Fired after printing |
|
|
445
|
+
| `zoomChange` | `EventEmitter<string>` | Fired when zoom changes (two-way binding) |
|
|
446
|
+
| `cursorChange` | `EventEmitter<string>` | Fired when cursor changes (two-way binding) |
|
|
447
|
+
| `scrollChange` | `EventEmitter<string>` | Fired when scroll changes (two-way binding) |
|
|
448
|
+
| `spreadChange` | `EventEmitter<string>` | Fired when spread changes (two-way binding) |
|
|
449
|
+
| `pageModeChange` | `EventEmitter<string>` | Fired when page mode changes (two-way binding) |
|
|
450
|
+
|
|
451
|
+
### Methods
|
|
452
|
+
|
|
453
|
+
| Method | Parameters | Returns | Description |
|
|
454
|
+
| -------------------------------------------------------- | ----------------------------------------------------------- | ---------------------------------------------------- | --------------------------------- |
|
|
455
|
+
| `refresh()` | - | `void` | Refresh viewer |
|
|
456
|
+
| `goToPage(page: number)` | `page: number` | `Promise<ActionExecutionResult>` | Navigate to specific page |
|
|
457
|
+
| `setPage(page: number)` | `page: number` | `Promise<ActionExecutionResult>` | Set current page |
|
|
458
|
+
| `setZoom(zoom: string)` | `zoom: string` | `Promise<ActionExecutionResult>` | Set zoom level |
|
|
459
|
+
| `setCursor(cursor: string)` | `cursor: 'select' \| 'hand' \| 'zoom'` | `Promise<ActionExecutionResult>` | Set cursor type |
|
|
460
|
+
| `setScroll(scroll: string)` | `scroll: 'vertical' \| 'horizontal' \| 'wrapped' \| 'page'` | `Promise<ActionExecutionResult>` | Set scroll mode |
|
|
461
|
+
| `setSpread(spread: string)` | `spread: 'none' \| 'odd' \| 'even'` | `Promise<ActionExecutionResult>` | Set spread mode |
|
|
462
|
+
| `setPageMode(mode: string)` | `mode: 'none' \| 'thumbs' \| 'bookmarks' \| 'attachments'` | `Promise<ActionExecutionResult>` | Set page mode |
|
|
463
|
+
| `triggerDownload()` | - | `Promise<ActionExecutionResult>` | Trigger download |
|
|
464
|
+
| `triggerPrint()` | - | `Promise<ActionExecutionResult>` | Trigger print |
|
|
465
|
+
| `triggerRotation(direction: string)` | `direction: 'cw' \| 'ccw'` | `Promise<ActionExecutionResult>` | Rotate document |
|
|
466
|
+
| `goToLastPage()` | - | `Promise<ActionExecutionResult>` | Navigate to last page |
|
|
467
|
+
| `sendViewerControlMessage(action: string, payload: any)` | `action: string, payload: any` | `Promise<any>` | Send custom control message |
|
|
468
|
+
| `getActionStatus(actionId: string)` | `actionId: string` | `Promise<ActionExecutionResult \| null>` | Get action status |
|
|
469
|
+
| `getQueueStatus()` | - | `{ queuedActions: number; executedActions: number }` | Get queue status |
|
|
470
|
+
| `clearActionQueue()` | - | `void` | Clear action queue |
|
|
471
|
+
| `reloadViewer()` | - | `void` | Reload viewer (alias for refresh) |
|
|
472
|
+
| `goBack()` | - | `void` | Go back in browser history |
|
|
473
|
+
| `closeViewer()` | - | `void` | Close viewer window |
|
|
474
|
+
| `getErrorTemplateData()` | - | `any` | Get error template data |
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
## 🎨 Examples
|
|
479
|
+
|
|
480
|
+
### 1. Basic PDF Viewer
|
|
481
|
+
|
|
482
|
+
```html
|
|
483
|
+
<ng2-pdfjs-viewer pdfSrc="assets/sample.pdf" [showSpinner]="true">
|
|
484
|
+
</ng2-pdfjs-viewer>
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### 2. Themed PDF Viewer
|
|
488
|
+
|
|
489
|
+
```html
|
|
490
|
+
<ng2-pdfjs-viewer
|
|
491
|
+
pdfSrc="assets/sample.pdf"
|
|
492
|
+
[theme]="'dark'"
|
|
493
|
+
[primaryColor]="'#ff6b6b'"
|
|
494
|
+
[backgroundColor]="'#2c3e50'"
|
|
495
|
+
>
|
|
496
|
+
</ng2-pdfjs-viewer>
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### 3. Custom Loading & Error
|
|
500
|
+
|
|
501
|
+
```html
|
|
502
|
+
<ng-template #loadingTemplate>
|
|
503
|
+
<div class="loading">
|
|
504
|
+
<mat-spinner></mat-spinner>
|
|
505
|
+
<p>Loading your document...</p>
|
|
506
|
+
</div>
|
|
507
|
+
</ng-template>
|
|
508
|
+
|
|
509
|
+
<ng-template #errorTemplate>
|
|
510
|
+
<div class="error">
|
|
511
|
+
<mat-icon>error_outline</mat-icon>
|
|
512
|
+
<h3>Oops! Something went wrong</h3>
|
|
513
|
+
<p>We couldn't load your PDF. Please try again.</p>
|
|
514
|
+
<button mat-button (click)="retry()">Retry</button>
|
|
515
|
+
</div>
|
|
516
|
+
</ng-template>
|
|
517
|
+
|
|
518
|
+
<ng2-pdfjs-viewer
|
|
519
|
+
pdfSrc="assets/sample.pdf"
|
|
520
|
+
[customSpinnerTpl]="loadingTemplate"
|
|
521
|
+
[customErrorTpl]="errorTemplate"
|
|
522
|
+
>
|
|
523
|
+
</ng2-pdfjs-viewer>
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### 4. Programmatic Control
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
export class PdfController {
|
|
530
|
+
@ViewChild("pdfViewer") pdfViewer!: PdfJsViewerComponent;
|
|
531
|
+
|
|
532
|
+
async loadDocument(url: string) {
|
|
533
|
+
this.pdfViewer.pdfSrc = url;
|
|
534
|
+
await this.pdfViewer.refresh();
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async goToPage(page: number) {
|
|
538
|
+
await this.pdfViewer.goToPage(page);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async setZoom(zoom: string) {
|
|
542
|
+
await this.pdfViewer.setZoom(zoom);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## 🔄 Migration Guide
|
|
550
|
+
|
|
551
|
+
### From v20.x to v25.x
|
|
552
|
+
|
|
553
|
+
#### Breaking Changes
|
|
554
|
+
|
|
555
|
+
1. **PDF.js Upgrade**: Updated to v5.3.93 - some APIs may have changed
|
|
556
|
+
2. **Theme System**: New theme properties replace old styling options
|
|
557
|
+
3. **Error Handling**: Template-based error system replaces HTML strings
|
|
558
|
+
|
|
559
|
+
#### Migration Steps
|
|
560
|
+
|
|
561
|
+
1. **Update Dependencies**
|
|
562
|
+
|
|
563
|
+
```bash
|
|
564
|
+
npm install ng2-pdfjs-viewer@latest
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
2. **Update Theme Configuration**
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
// Old way
|
|
571
|
+
[customCSS]="'body { background: red; }'"
|
|
572
|
+
|
|
573
|
+
// New way
|
|
574
|
+
[theme]="'light'"
|
|
575
|
+
[primaryColor]="'#ff0000'"
|
|
576
|
+
[backgroundColor]="'#ffffff'"
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
3. **Update Error Handling**
|
|
580
|
+
|
|
581
|
+
```html
|
|
582
|
+
<!-- Old way -->
|
|
583
|
+
[errorHtml]="'<div>Custom error</div>'"
|
|
584
|
+
|
|
585
|
+
<!-- New way -->
|
|
586
|
+
<ng-template #errorTemplate>
|
|
587
|
+
<div>Custom error</div>
|
|
588
|
+
</ng-template>
|
|
589
|
+
<ng2-pdfjs-viewer [customErrorTpl]="errorTemplate"></ng2-pdfjs-viewer>
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
4. **Update Spinner Handling**
|
|
593
|
+
|
|
594
|
+
```html
|
|
595
|
+
<!-- Old way -->
|
|
596
|
+
[spinnerHtml]="'<div class=\"spinner\">Loading...</div>'"
|
|
597
|
+
|
|
598
|
+
<!-- New way -->
|
|
599
|
+
<ng-template #spinnerTemplate>
|
|
600
|
+
<div class="spinner">Loading...</div>
|
|
601
|
+
</ng-template>
|
|
602
|
+
<ng2-pdfjs-viewer [customSpinnerTpl]="spinnerTemplate"></ng2-pdfjs-viewer>
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
```typescript
|
|
606
|
+
// Old way
|
|
607
|
+
this.pdfViewer.setSpinnerHtml('<div>Loading...</div>');
|
|
608
|
+
|
|
609
|
+
// New way
|
|
610
|
+
// Use [customSpinnerTpl] with ng-template
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
---
|
|
614
|
+
|
|
615
|
+
## Deprecated Features
|
|
616
|
+
|
|
617
|
+
The following features are deprecated and will be removed in future versions:
|
|
618
|
+
|
|
619
|
+
### Deprecated Properties
|
|
620
|
+
|
|
621
|
+
| Deprecated | Replacement | Description |
|
|
622
|
+
| ----------------- | -------------------- | --------------------------------------------- |
|
|
623
|
+
| `[startDownload]` | `[downloadOnLoad]` | Download document automatically when it opens |
|
|
624
|
+
| `[startPrint]` | `[printOnLoad]` | Print document automatically when it opens |
|
|
625
|
+
| `[errorHtml]` | `[customErrorTpl]` | Custom error HTML (use template instead) |
|
|
626
|
+
| `[errorTemplate]` | `[customErrorTpl]` | Custom error template (renamed) |
|
|
627
|
+
| `[spinnerHtml]` | `[customSpinnerTpl]` | Custom spinner HTML (use template instead) |
|
|
628
|
+
|
|
629
|
+
### Deprecated Methods
|
|
630
|
+
|
|
631
|
+
| Deprecated | Replacement | Description |
|
|
632
|
+
| ------------------ | ------------------------ | ---------------------------------------------- |
|
|
633
|
+
| `setErrorHtml()` | Use `[customErrorTpl]` | Set custom error HTML (use template instead) |
|
|
634
|
+
| `setSpinnerHtml()` | Use `[customSpinnerTpl]` | Set custom spinner HTML (use template instead) |
|
|
635
|
+
|
|
636
|
+
### Migration Help
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
// Deprecated - Error Handling
|
|
640
|
+
this.pdfViewer.setErrorHtml("<div>Error</div>");
|
|
641
|
+
|
|
642
|
+
// New way - Error Handling
|
|
643
|
+
// Use [customErrorTpl] with ng-template
|
|
644
|
+
|
|
645
|
+
// Deprecated - Spinner Handling
|
|
646
|
+
this.pdfViewer.setSpinnerHtml("<div>Loading...</div>");
|
|
647
|
+
|
|
648
|
+
// New way - Spinner Handling
|
|
649
|
+
// Use [customSpinnerTpl] with ng-template
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
---
|
|
653
|
+
|
|
654
|
+
## 📚 Additional Resources
|
|
655
|
+
|
|
656
|
+
- **[Custom CSS Examples](Custom-CSS-Examples.md)** - Complete styling guide with theme customization examples
|
|
657
|
+
- **[Error Display Examples](Error-Display-Examples.md)** - Custom error template examples and styling options
|
|
658
|
+
- **[Contributing Guide](CONTRIBUTING.md)** - How to contribute to the project
|
|
659
|
+
|
|
660
|
+
## 🤝 Contributing
|
|
661
|
+
|
|
662
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
663
|
+
|
|
664
|
+
### Development Setup
|
|
665
|
+
|
|
666
|
+
```bash
|
|
667
|
+
# Clone the repository
|
|
668
|
+
git clone https://github.com/intbot/ng2-pdfjs-viewer.git
|
|
669
|
+
|
|
670
|
+
# Install dependencies
|
|
671
|
+
npm install
|
|
672
|
+
|
|
673
|
+
# Clear Angular cache (Windows)
|
|
674
|
+
Remove-Item -Recurse -Force "SampleApp\.angular"
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
# Build and test - All at once (Windows)
|
|
678
|
+
@test.bat
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
### Reporting Issues
|
|
682
|
+
|
|
683
|
+
- 🐛 **Bug Reports**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
|
|
684
|
+
- 💡 **Feature Requests**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
|
|
685
|
+
- 📚 **Documentation**: [GitHub Wiki](https://github.com/intbot/ng2-pdfjs-viewer/wiki)
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
## 📄 License
|
|
690
|
+
|
|
691
|
+
This project is licensed under the **Apache License 2.0 + Commons Clause License Condition v1.0** - see the [LICENSE](LICENSE) file for details.
|
|
692
|
+
|
|
693
|
+
---
|
|
694
|
+
|
|
695
|
+
## 🙏 Acknowledgments
|
|
696
|
+
|
|
697
|
+
- **Mozilla PDF.js Team** - For the amazing PDF.js library
|
|
698
|
+
- **Angular Team** - For the excellent framework
|
|
699
|
+
- **Community Contributors** - For bug reports, feature requests, and contributions
|
|
700
|
+
- **7+ Million Users** - For trusting us with your PDF viewing needs
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
## 📞 Support
|
|
705
|
+
|
|
706
|
+
- 📖 **Documentation**: [GitHub Wiki](https://github.com/intbot/ng2-pdfjs-viewer/wiki)
|
|
707
|
+
- 💬 **Community**: [GitHub Discussions](https://github.com/intbot/ng2-pdfjs-viewer/discussions)
|
|
708
|
+
- 🐛 **Issues**: [GitHub Issues](https://github.com/intbot/ng2-pdfjs-viewer/issues)
|
|
709
|
+
- 📧 **Email**: codehippie1@gmail.com
|
|
710
|
+
|
|
711
|
+
---
|
|
712
|
+
|
|
713
|
+
<div align="center">
|
|
714
|
+
|
|
715
|
+
**Made with ❤️ by the ng2-pdfjs-viewer team**
|
|
716
|
+
|
|
717
|
+
[](https://github.com/intbot/ng2-pdfjs-viewer)
|
|
718
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
719
|
+
[](https://angular.dev/overview)
|
|
720
|
+
|
|
721
|
+
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng2-pdfjs-viewer",
|
|
3
|
-
"version": "25.0.
|
|
3
|
+
"version": "25.0.3",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Aneesh Goapalakrishnan",
|
|
6
6
|
"email": "codehippie1@gmail.com"
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"viewer.html"
|
|
42
42
|
],
|
|
43
43
|
"license": "Apache-2.0 + Commons Clause",
|
|
44
|
+
"readme": "README.md",
|
|
44
45
|
"sideEffects": false,
|
|
45
46
|
"dependencies": {
|
|
46
47
|
"tslib": "^2.3.0"
|