ng2-pdfjs-viewer 26.0.0 → 26.0.1
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.
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng2-pdfjs-viewer",
|
|
3
|
-
"version": "26.0.
|
|
3
|
+
"version": "26.0.1",
|
|
4
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. 7M+ downloads, mobile-first, production-ready.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aneesh Goapalakrishnan",
|
|
@@ -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;
|