ng2-pdfjs-viewer 26.0.0 → 26.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<img src="https://raw.githubusercontent.com/intbot/ng2-pdfjs-viewer/master/lib/
|
|
3
|
+
<img src="https://raw.githubusercontent.com/intbot/ng2-pdfjs-viewer/master/lib/pdf-viewer-banner.png" alt="#1 Angular PDF Viewer — ng2-pdfjs-viewer: AI-enabled, feature-rich and comprehensive. 8.3M+ downloads, 0 runtime dependencies, 8 years (since 2018), Angular 10–22." width="880" />
|
|
4
4
|
|
|
5
5
|
# ng2-pdfjs-viewer
|
|
6
6
|
|
|
7
7
|
**A complete PDF experience in one Angular component — view, annotate, sign, fill forms, search, and read aloud, powered by Mozilla PDF.js.**
|
|
8
8
|
|
|
9
|
-
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
10
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
11
|
+
[](https://www.npmjs.com/package/ng2-pdfjs-viewer)
|
|
12
|
+
[](https://github.com/intbot/ng2-pdfjs-viewer/blob/master/BILL-OF-MATERIALS.md)
|
|
13
|
+
[](https://github.com/mozilla/pdf.js)
|
|
14
|
+
[](https://angular.dev)
|
|
15
|
+
[](https://github.com/intbot/ng2-pdfjs-viewer/blob/master/LICENSE)
|
|
16
|
+
[](https://github.com/intbot/ng2-pdfjs-viewer)
|
|
16
17
|
[](https://scorecard.dev/viewer/?uri=github.com/intbot/ng2-pdfjs-viewer)
|
|
17
18
|
|
|
18
19
|
[**Live demo**](https://angular-pdf-viewer-demo.vercel.app/) · [**Documentation**](https://angular-pdf-viewer-docs.vercel.app/) · [**API reference**](https://angular-pdf-viewer-docs.vercel.app/docs/api/component-inputs) · [**Changelog**](https://github.com/intbot/ng2-pdfjs-viewer/blob/master/CHANGELOG.md)
|
|
@@ -22,11 +23,11 @@
|
|
|
22
23
|
---
|
|
23
24
|
|
|
24
25
|
Drop a production PDF viewer into any Angular app with a single tag. ng2-pdfjs-viewer wraps
|
|
25
|
-
|
|
26
|
+
**PDF.js 6** in one declarative `<ng2-pdfjs-viewer>` component: rendering, navigation,
|
|
26
27
|
search, printing, theming, annotations, e-signatures, AcroForms, read-aloud, and a bring-your-own
|
|
27
28
|
AI assistant — all driven by typed `@Input()`s and `@Output()` events, no iframe plumbing of your own.
|
|
28
29
|
|
|
29
|
-
Shipping since **2018**, **
|
|
30
|
+
Shipping since **2018**, **8.3+ million downloads**, mobile-first, and built & verified on **Angular 22**
|
|
30
31
|
while keeping a wide `>=10` peer range so existing apps upgrade without churn.
|
|
31
32
|
|
|
32
33
|
```bash
|
|
@@ -43,7 +44,7 @@ That's the whole integration. [Wire up the assets](#-quick-start) and you have a
|
|
|
43
44
|
|
|
44
45
|
| | |
|
|
45
46
|
|---|---|
|
|
46
|
-
| 📄 **View anything** | Crisp
|
|
47
|
+
| 📄 **View anything** | Crisp, high-fidelity rendering, zoom, navigation, thumbnails, outline, printing — embedded, in a new tab, or a popout window. |
|
|
47
48
|
| ✍️ **Annotate & sign** | Highlight, draw, free-text, and stamp editors; opt-in draw/type/upload **signature** editor and threaded comments. Export and restore edits for a full server round-trip. |
|
|
48
49
|
| 🧾 **Fill forms** | Two-way AcroForm binding — read and write field values from your component, save the filled document as a blob. |
|
|
49
50
|
| 🔎 **Search in code** | Programmatic `search()` with totals, per-page counts, and next/previous navigation — build your own find UI. |
|
|
@@ -197,13 +198,13 @@ See [CONTRIBUTING.md](https://github.com/intbot/ng2-pdfjs-viewer/blob/master/CON
|
|
|
197
198
|
|
|
198
199
|
## 📄 License
|
|
199
200
|
|
|
200
|
-
[Apache-2.0
|
|
201
|
+
[Apache-2.0 (Commons Clause)](https://github.com/intbot/ng2-pdfjs-viewer/blob/master/LICENSE). Free to use, modify, and self-host; the Commons
|
|
201
202
|
Clause restricts selling the software itself as a hosted/commercial product.
|
|
202
203
|
|
|
203
204
|
## 🙏 Acknowledgments
|
|
204
205
|
|
|
205
206
|
Built on the excellent [Mozilla PDF.js](https://github.com/mozilla/pdf.js), and shaped over the
|
|
206
|
-
years by a community of contributors and
|
|
207
|
+
years by a community of contributors and 8.3+ million downloads' worth of real-world use.
|
|
207
208
|
|
|
208
209
|
---
|
|
209
210
|
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
// service, a plain script). The full component re-exports these symbols from
|
|
14
14
|
// the package root for backwards compatibility.
|
|
15
15
|
//
|
|
16
|
+
// SECURITY: this sends a fetch from wherever you construct it — in a browser
|
|
17
|
+
// app, that is the user's browser. Don't point `endpoint` directly at a hosted
|
|
18
|
+
// cloud LLM (OpenAI, Azure, …): the API key would be exposed to the client, and
|
|
19
|
+
// most providers block direct browser calls via CORS. Use a local model
|
|
20
|
+
// (Ollama, LM Studio) or your own backend proxy. See the AI Assistant guide.
|
|
21
|
+
//
|
|
16
22
|
// Usage:
|
|
17
23
|
// import { PdfAiAssistant } from "ng2-pdfjs-viewer/ai";
|
|
18
24
|
// const text = await viewer.getDocumentText();
|
|
@@ -1687,6 +1687,7 @@ class PdfJsViewerComponent {
|
|
|
1687
1687
|
const eventBus = this.PDFViewerApplication.eventBus;
|
|
1688
1688
|
const handlers = {
|
|
1689
1689
|
documentloaded: () => {
|
|
1690
|
+
this.documentLoaded = true;
|
|
1690
1691
|
if (this.diagnosticLogs)
|
|
1691
1692
|
console.debug("PdfJsViewer: The document has now been loaded!");
|
|
1692
1693
|
this.onDocumentLoad.emit();
|
|
@@ -2023,12 +2024,39 @@ class PdfJsViewerComponent {
|
|
|
2023
2024
|
* PDF.js text layer. The raw material for BYO-AI chat/summarize flows.
|
|
2024
2025
|
*/
|
|
2025
2026
|
async getDocumentText(from, to) {
|
|
2027
|
+
// The document may not have finished loading the instant this is called
|
|
2028
|
+
// (e.g. an AI 'ask' fired immediately after the viewer appears). Wait for
|
|
2029
|
+
// 'documentloaded' so we don't extract empty text; fall back on timeout.
|
|
2030
|
+
if (!this.documentLoaded) {
|
|
2031
|
+
await this.waitForDocumentLoad(15000);
|
|
2032
|
+
}
|
|
2026
2033
|
const result = await this.dispatchAction("get-document-text", { from, to }, "user-interaction");
|
|
2027
2034
|
if (!result.success) {
|
|
2028
2035
|
throw new Error(result.error || "getDocumentText failed");
|
|
2029
2036
|
}
|
|
2030
2037
|
return result.data ?? [];
|
|
2031
2038
|
}
|
|
2039
|
+
/**
|
|
2040
|
+
* Resolve once the current document has loaded, or after timeoutMs (in which
|
|
2041
|
+
* case callers proceed with whatever the viewer can provide). Never rejects.
|
|
2042
|
+
*/
|
|
2043
|
+
waitForDocumentLoad(timeoutMs) {
|
|
2044
|
+
if (this.documentLoaded)
|
|
2045
|
+
return Promise.resolve();
|
|
2046
|
+
return new Promise((resolve) => {
|
|
2047
|
+
let settled = false;
|
|
2048
|
+
const finish = () => {
|
|
2049
|
+
if (settled)
|
|
2050
|
+
return;
|
|
2051
|
+
settled = true;
|
|
2052
|
+
sub.unsubscribe();
|
|
2053
|
+
clearTimeout(timer);
|
|
2054
|
+
resolve();
|
|
2055
|
+
};
|
|
2056
|
+
const sub = this.onDocumentLoad.subscribe(() => finish());
|
|
2057
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2032
2060
|
/**
|
|
2033
2061
|
* Read the document aloud from the current (or given) page using the
|
|
2034
2062
|
* browser's speech synthesis. Progress arrives on onReadAloudStateChange.
|
|
@@ -2178,6 +2206,8 @@ class PdfJsViewerComponent {
|
|
|
2178
2206
|
// A new load lifts the failed-document latch (the documentInit relay
|
|
2179
2207
|
// also clears it, but that is enablement-gated and can race fast loads)
|
|
2180
2208
|
this.documentLoadFailed = false;
|
|
2209
|
+
// Text isn't extractable until the new document finishes loading.
|
|
2210
|
+
this.documentLoaded = false;
|
|
2181
2211
|
this.cdr.markForCheck();
|
|
2182
2212
|
if (!this.setupExternalWindow()) {
|
|
2183
2213
|
return; // popup blocked - nothing to navigate
|
|
@@ -2389,6 +2419,9 @@ class PdfJsViewerComponent {
|
|
|
2389
2419
|
// actions dispatched against a failed load settle immediately instead of
|
|
2390
2420
|
// queueing forever.
|
|
2391
2421
|
documentLoadFailed = false;
|
|
2422
|
+
// True once the current document fires 'documentloaded'. getDocumentText()
|
|
2423
|
+
// awaits this so an AI 'ask' fired before render doesn't extract empty text.
|
|
2424
|
+
documentLoaded = false;
|
|
2392
2425
|
// Universal Action Dispatcher - ALL actions go through readiness-based queuing
|
|
2393
2426
|
dispatchAction(action, payload, source = "property-change", level) {
|
|
2394
2427
|
if (this.externalWindow && !this.externalWindowWarned) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng2-pdfjs-viewer",
|
|
3
|
-
"version": "26.0.
|
|
4
|
-
"description": "The most comprehensive Angular PDF viewer, powered by Mozilla PDF.js 6 — view, annotate, sign, fill forms, search, and read aloud from one component.
|
|
3
|
+
"version": "26.0.2",
|
|
4
|
+
"description": "The most comprehensive Angular PDF viewer, powered by Mozilla PDF.js 6 — view, annotate, sign, fill forms, search, and read aloud from one component. 8.3M+ downloads, mobile-first, production-ready.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aneesh Goapalakrishnan",
|
|
7
7
|
"email": "codehippie1@gmail.com"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"accessibility",
|
|
52
52
|
"open-source"
|
|
53
53
|
],
|
|
54
|
-
"license": "Apache-2.0
|
|
54
|
+
"license": "Apache-2.0 (Commons Clause)",
|
|
55
55
|
"readme": "README.md",
|
|
56
56
|
"exports": {
|
|
57
57
|
"./package.json": {
|
|
@@ -166,6 +166,12 @@ body #outerContainer.sidebar-right.viewsManagerOpen #loadingBar {
|
|
|
166
166
|
/* Light theme defaults */
|
|
167
167
|
.ng2-theme-light,
|
|
168
168
|
.ng2-theme-light-active {
|
|
169
|
+
/* Pin the UA color-scheme so PDF.js's light-dark() colours (toolbar/menu
|
|
170
|
+
icons, form controls, scrollbars) resolve to the SELECTED theme instead of
|
|
171
|
+
the OS preference. Without this, when the app theme differs from the OS
|
|
172
|
+
theme the icons inherit :root's `color-scheme: light dark` and become
|
|
173
|
+
invisible (e.g. light icons on a light toolbar). */
|
|
174
|
+
color-scheme: light;
|
|
169
175
|
--ng2-default-bg: #d4d4d7; /* PDF.js original grey background */
|
|
170
176
|
--ng2-default-text: #000000;
|
|
171
177
|
--ng2-default-toolbar: #f9f9f9;
|
|
@@ -175,6 +181,7 @@ body #outerContainer.sidebar-right.viewsManagerOpen #loadingBar {
|
|
|
175
181
|
/* Dark theme defaults */
|
|
176
182
|
.ng2-theme-dark,
|
|
177
183
|
.ng2-theme-dark-active {
|
|
184
|
+
color-scheme: dark;
|
|
178
185
|
--ng2-default-bg: #1e1e1e;
|
|
179
186
|
--ng2-default-text: #ffffff;
|
|
180
187
|
--ng2-default-toolbar: #333333;
|
|
@@ -554,6 +554,11 @@ declare class PdfJsViewerComponent implements OnInit, OnDestroy, OnChanges, Afte
|
|
|
554
554
|
* PDF.js text layer. The raw material for BYO-AI chat/summarize flows.
|
|
555
555
|
*/
|
|
556
556
|
getDocumentText(from?: number, to?: number): Promise<DocumentPageText[]>;
|
|
557
|
+
/**
|
|
558
|
+
* Resolve once the current document has loaded, or after timeoutMs (in which
|
|
559
|
+
* case callers proceed with whatever the viewer can provide). Never rejects.
|
|
560
|
+
*/
|
|
561
|
+
private waitForDocumentLoad;
|
|
557
562
|
/**
|
|
558
563
|
* Read the document aloud from the current (or given) page using the
|
|
559
564
|
* browser's speech synthesis. Progress arrives on onReadAloudStateChange.
|
|
@@ -606,6 +611,7 @@ declare class PdfJsViewerComponent implements OnInit, OnDestroy, OnChanges, Afte
|
|
|
606
611
|
private navigateToViewer;
|
|
607
612
|
private externalWindowWarned;
|
|
608
613
|
private documentLoadFailed;
|
|
614
|
+
private documentLoaded;
|
|
609
615
|
private dispatchAction;
|
|
610
616
|
private getRequiredReadinessLevel;
|
|
611
617
|
private hasRequiredReadiness;
|