@embedpdf/engines 2.0.0-next.2 → 2.0.0
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 +15 -9
- package/dist/browser-C6QEa8uk.cjs +2 -0
- package/dist/browser-C6QEa8uk.cjs.map +1 -0
- package/dist/browser-awZxztMA.js +76 -0
- package/dist/browser-awZxztMA.js.map +1 -0
- package/dist/{engine-B-RaFU77.js → direct-engine-DuLFAbiv.js} +211 -520
- package/dist/direct-engine-DuLFAbiv.js.map +1 -0
- package/dist/direct-engine-JeNRkc7w.cjs +2 -0
- package/dist/direct-engine-JeNRkc7w.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +301 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/converters/browser.d.ts +33 -0
- package/dist/lib/converters/index.cjs +1 -1
- package/dist/lib/converters/index.cjs.map +1 -1
- package/dist/lib/converters/index.d.ts +3 -51
- package/dist/lib/converters/index.js +6 -1
- package/dist/lib/converters/index.js.map +1 -1
- package/dist/lib/converters/node.d.ts +51 -0
- package/dist/lib/converters/types.d.ts +6 -3
- package/dist/lib/image-encoder/image-encoder-worker.d.ts +24 -0
- package/dist/lib/image-encoder/index.d.ts +2 -0
- package/dist/lib/image-encoder/worker-pool.d.ts +61 -0
- package/dist/lib/orchestrator/index.d.ts +16 -0
- package/dist/lib/orchestrator/pdf-engine.d.ts +99 -0
- package/dist/lib/orchestrator/pdfium-native-runner.d.ts +65 -0
- package/dist/lib/orchestrator/remote-executor.d.ts +93 -0
- package/dist/lib/orchestrator/task-queue.d.ts +87 -0
- package/dist/lib/pdfium/engine.d.ts +52 -93
- package/dist/lib/pdfium/index.cjs +1 -1
- package/dist/lib/pdfium/index.cjs.map +1 -1
- package/dist/lib/pdfium/index.d.ts +6 -1
- package/dist/lib/pdfium/index.js +15 -8
- package/dist/lib/pdfium/index.js.map +1 -1
- package/dist/lib/pdfium/runner.d.ts +2 -2
- package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
- package/dist/lib/pdfium/web/direct-engine.cjs.map +1 -1
- package/dist/lib/pdfium/web/direct-engine.d.ts +33 -2
- package/dist/lib/pdfium/web/direct-engine.js +5 -9
- package/dist/lib/pdfium/web/direct-engine.js.map +1 -1
- package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
- package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
- package/dist/lib/pdfium/web/worker-engine.d.ts +40 -4
- package/dist/lib/pdfium/web/worker-engine.js +412 -9
- package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
- package/dist/lib/webworker/engine.cjs +1 -1
- package/dist/lib/webworker/engine.cjs.map +1 -1
- package/dist/lib/webworker/engine.d.ts +0 -6
- package/dist/lib/webworker/engine.js +0 -13
- package/dist/lib/webworker/engine.js.map +1 -1
- package/dist/lib/webworker/runner.d.ts +0 -12
- package/dist/pdf-engine-BVNF_Yo9.js +790 -0
- package/dist/pdf-engine-BVNF_Yo9.js.map +1 -0
- package/dist/pdf-engine-C3JeKij1.cjs +2 -0
- package/dist/pdf-engine-C3JeKij1.cjs.map +1 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +5 -13
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +5 -13
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/hooks/use-pdfium-engine.d.ts +1 -0
- package/dist/shared-react/hooks/use-pdfium-engine.d.ts +1 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +3 -11
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +3 -12
- package/dist/vue/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/engine-B-RaFU77.js.map +0 -1
- package/dist/engine-CXnLqg_9.cjs +0 -2
- package/dist/engine-CXnLqg_9.cjs.map +0 -1
- package/dist/index-Cp8_nZYM.js +0 -342
- package/dist/index-Cp8_nZYM.js.map +0 -1
- package/dist/index-DuHK0qLu.cjs +0 -2
- package/dist/index-DuHK0qLu.cjs.map +0 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { init } from "@embedpdf/pdfium";
|
|
2
|
+
import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
|
|
3
|
+
import { P as PdfEngine } from "./pdf-engine-BVNF_Yo9.js";
|
|
4
|
+
import { b as browserImageDataToBlobConverter } from "./browser-awZxztMA.js";
|
|
2
5
|
function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
|
|
3
6
|
let buffer = wasmModule.wasmExports.malloc(defaultLength);
|
|
4
7
|
for (let i = 0; i < defaultLength; i++) {
|
|
@@ -482,42 +485,17 @@ var PdfiumErrorCode = /* @__PURE__ */ ((PdfiumErrorCode2) => {
|
|
|
482
485
|
PdfiumErrorCode2[PdfiumErrorCode2["XFALayout"] = 8] = "XFALayout";
|
|
483
486
|
return PdfiumErrorCode2;
|
|
484
487
|
})(PdfiumErrorCode || {});
|
|
485
|
-
class
|
|
486
|
-
constructor(message) {
|
|
487
|
-
super(message);
|
|
488
|
-
this.name = "OffscreenCanvasError";
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
const browserImageDataToBlobConverter = (getImageData, imageType = "image/webp", quality) => {
|
|
492
|
-
if (typeof OffscreenCanvas === "undefined") {
|
|
493
|
-
return Promise.reject(
|
|
494
|
-
new OffscreenCanvasError(
|
|
495
|
-
"OffscreenCanvas is not available in this environment. This converter is intended for browser use only. Falling back to WASM-based image encoding."
|
|
496
|
-
)
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
const pdfImage = getImageData();
|
|
500
|
-
const imageData = new ImageData(pdfImage.data, pdfImage.width, pdfImage.height);
|
|
501
|
-
const off = new OffscreenCanvas(imageData.width, imageData.height);
|
|
502
|
-
off.getContext("2d").putImageData(imageData, 0, 0);
|
|
503
|
-
return off.convertToBlob({ type: imageType, quality });
|
|
504
|
-
};
|
|
505
|
-
class PdfiumEngine {
|
|
488
|
+
class PdfiumNative {
|
|
506
489
|
/**
|
|
507
|
-
* Create an instance of
|
|
490
|
+
* Create an instance of PdfiumNative and initialize PDFium
|
|
508
491
|
* @param wasmModule - pdfium wasm module
|
|
509
|
-
* @param
|
|
510
|
-
* @param imageDataToBlobConverter - function to convert ImageData to Blob
|
|
492
|
+
* @param options - configuration options
|
|
511
493
|
*/
|
|
512
494
|
constructor(pdfiumModule, options = {}) {
|
|
513
495
|
this.pdfiumModule = pdfiumModule;
|
|
514
496
|
this.memoryLeakCheckInterval = null;
|
|
515
|
-
const {
|
|
516
|
-
logger = new NoopLogger(),
|
|
517
|
-
imageDataConverter = browserImageDataToBlobConverter
|
|
518
|
-
} = options;
|
|
497
|
+
const { logger = new NoopLogger() } = options;
|
|
519
498
|
this.logger = logger;
|
|
520
|
-
this.imageDataConverter = imageDataConverter;
|
|
521
499
|
this.memoryManager = new MemoryManager(this.pdfiumModule, this.logger);
|
|
522
500
|
this.cache = new PdfCache(this.pdfiumModule, this.memoryManager);
|
|
523
501
|
if (this.logger.isEnabled("debug")) {
|
|
@@ -525,18 +503,10 @@ class PdfiumEngine {
|
|
|
525
503
|
this.memoryManager.checkLeaks();
|
|
526
504
|
}, 1e4);
|
|
527
505
|
}
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.initialize}
|
|
531
|
-
*
|
|
532
|
-
* @public
|
|
533
|
-
*/
|
|
534
|
-
initialize() {
|
|
535
506
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "initialize");
|
|
536
507
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Initialize`, "Begin", "General");
|
|
537
508
|
this.pdfiumModule.PDFiumExt_Init();
|
|
538
509
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Initialize`, "End", "General");
|
|
539
|
-
return PdfTaskHelper.resolve(true);
|
|
540
510
|
}
|
|
541
511
|
/**
|
|
542
512
|
* {@inheritDoc @embedpdf/models!PdfEngine.destroy}
|
|
@@ -581,165 +551,6 @@ class PdfiumEngine {
|
|
|
581
551
|
if (bytes) this.memoryManager.free(ptr);
|
|
582
552
|
}
|
|
583
553
|
}
|
|
584
|
-
/**
|
|
585
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.openDocumentUrl}
|
|
586
|
-
*
|
|
587
|
-
* @public
|
|
588
|
-
*/
|
|
589
|
-
openDocumentUrl(file, options) {
|
|
590
|
-
const mode = (options == null ? void 0 : options.mode) ?? "auto";
|
|
591
|
-
const password = (options == null ? void 0 : options.password) ?? "";
|
|
592
|
-
const requestOptions = options == null ? void 0 : options.requestOptions;
|
|
593
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentUrl called", file.url, mode);
|
|
594
|
-
const task = PdfTaskHelper.create();
|
|
595
|
-
(async () => {
|
|
596
|
-
try {
|
|
597
|
-
const fetchFullTask = await this.fetchFullAndOpen(file, password, requestOptions);
|
|
598
|
-
fetchFullTask.wait(
|
|
599
|
-
(doc) => task.resolve(doc),
|
|
600
|
-
(err) => task.reject(err.reason)
|
|
601
|
-
);
|
|
602
|
-
} catch (err) {
|
|
603
|
-
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "openDocumentUrl error", err);
|
|
604
|
-
task.reject({
|
|
605
|
-
code: PdfErrorCode.Unknown,
|
|
606
|
-
message: String(err)
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
})();
|
|
610
|
-
return task;
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Check if the server supports range requests:
|
|
614
|
-
* Sends a HEAD request and sees if 'Accept-Ranges: bytes'.
|
|
615
|
-
*/
|
|
616
|
-
async checkRangeSupport(url, requestOptions) {
|
|
617
|
-
try {
|
|
618
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "checkRangeSupport", url);
|
|
619
|
-
const headResponse = await fetch(url, {
|
|
620
|
-
method: "HEAD",
|
|
621
|
-
headers: requestOptions == null ? void 0 : requestOptions.headers,
|
|
622
|
-
credentials: requestOptions == null ? void 0 : requestOptions.credentials
|
|
623
|
-
});
|
|
624
|
-
const fileLength = headResponse.headers.get("Content-Length");
|
|
625
|
-
const acceptRanges = headResponse.headers.get("Accept-Ranges");
|
|
626
|
-
if (acceptRanges === "bytes") {
|
|
627
|
-
return {
|
|
628
|
-
supportsRanges: true,
|
|
629
|
-
fileLength: parseInt(fileLength ?? "0"),
|
|
630
|
-
content: null
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
const testResponse = await fetch(url, {
|
|
634
|
-
headers: { ...requestOptions == null ? void 0 : requestOptions.headers, Range: "bytes=0-1" },
|
|
635
|
-
credentials: requestOptions == null ? void 0 : requestOptions.credentials
|
|
636
|
-
});
|
|
637
|
-
if (testResponse.status === 200) {
|
|
638
|
-
const content = await testResponse.arrayBuffer();
|
|
639
|
-
return {
|
|
640
|
-
supportsRanges: false,
|
|
641
|
-
fileLength: parseInt(fileLength ?? "0"),
|
|
642
|
-
content
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
return {
|
|
646
|
-
supportsRanges: testResponse.status === 206,
|
|
647
|
-
fileLength: parseInt(fileLength ?? "0"),
|
|
648
|
-
content: null
|
|
649
|
-
};
|
|
650
|
-
} catch (e) {
|
|
651
|
-
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "checkRangeSupport failed", e);
|
|
652
|
-
throw new Error("Failed to check range support: " + e);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Fully fetch the file (using fetch) into an ArrayBuffer,
|
|
657
|
-
* then call openDocumentFromBuffer.
|
|
658
|
-
*/
|
|
659
|
-
async fetchFullAndOpen(file, password, requestOptions) {
|
|
660
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "fetchFullAndOpen", file.url);
|
|
661
|
-
const response = await fetch(file.url, {
|
|
662
|
-
headers: requestOptions == null ? void 0 : requestOptions.headers,
|
|
663
|
-
credentials: requestOptions == null ? void 0 : requestOptions.credentials
|
|
664
|
-
});
|
|
665
|
-
if (!response.ok) {
|
|
666
|
-
throw new Error(`Could not fetch PDF: ${response.statusText}`);
|
|
667
|
-
}
|
|
668
|
-
const arrayBuf = await response.arrayBuffer();
|
|
669
|
-
const pdfFile = {
|
|
670
|
-
id: file.id,
|
|
671
|
-
content: arrayBuf
|
|
672
|
-
};
|
|
673
|
-
return this.openDocumentBuffer(pdfFile, { password });
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Use your synchronous partial-loading approach:
|
|
677
|
-
* - In your snippet, it's done via `openDocumentFromLoader`.
|
|
678
|
-
* - We'll do a synchronous XHR read callback that pulls
|
|
679
|
-
* the desired byte ranges.
|
|
680
|
-
*/
|
|
681
|
-
async openDocumentWithRangeRequest(file, password, knownFileLength, requestOptions) {
|
|
682
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentWithRangeRequest", file.url);
|
|
683
|
-
const fileLength = knownFileLength ?? (await this.retrieveFileLength(file.url, requestOptions)).fileLength;
|
|
684
|
-
const callback = (offset, length) => {
|
|
685
|
-
const xhr = new XMLHttpRequest();
|
|
686
|
-
xhr.open("GET", file.url, false);
|
|
687
|
-
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
688
|
-
xhr.setRequestHeader("Range", `bytes=${offset}-${offset + length - 1}`);
|
|
689
|
-
if (requestOptions == null ? void 0 : requestOptions.headers) {
|
|
690
|
-
Object.entries(requestOptions.headers).forEach(([key, value]) => {
|
|
691
|
-
xhr.setRequestHeader(key, value);
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
if (requestOptions == null ? void 0 : requestOptions.credentials) {
|
|
695
|
-
xhr.withCredentials = requestOptions.credentials === "include";
|
|
696
|
-
}
|
|
697
|
-
xhr.send(null);
|
|
698
|
-
if (xhr.status === 206 || xhr.status === 200) {
|
|
699
|
-
return this.convertResponseToUint8Array(xhr.responseText);
|
|
700
|
-
}
|
|
701
|
-
throw new Error(`Range request failed with status ${xhr.status}`);
|
|
702
|
-
};
|
|
703
|
-
return this.openDocumentFromLoader(
|
|
704
|
-
{
|
|
705
|
-
id: file.id,
|
|
706
|
-
fileLength,
|
|
707
|
-
callback
|
|
708
|
-
},
|
|
709
|
-
password
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Helper to do a HEAD request or partial GET to find file length.
|
|
714
|
-
*/
|
|
715
|
-
async retrieveFileLength(url, requestOptions) {
|
|
716
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "retrieveFileLength", url);
|
|
717
|
-
const resp = await fetch(url, {
|
|
718
|
-
method: "HEAD",
|
|
719
|
-
headers: requestOptions == null ? void 0 : requestOptions.headers,
|
|
720
|
-
credentials: requestOptions == null ? void 0 : requestOptions.credentials
|
|
721
|
-
});
|
|
722
|
-
if (!resp.ok) {
|
|
723
|
-
throw new Error(`Failed HEAD request for file length: ${resp.statusText}`);
|
|
724
|
-
}
|
|
725
|
-
const lenStr = resp.headers.get("Content-Length") || "0";
|
|
726
|
-
const fileLength = parseInt(lenStr, 10) || 0;
|
|
727
|
-
if (!fileLength) {
|
|
728
|
-
throw new Error(`Content-Length not found or zero.`);
|
|
729
|
-
}
|
|
730
|
-
return { fileLength };
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* Convert response text (x-user-defined) to a Uint8Array
|
|
734
|
-
* for partial data.
|
|
735
|
-
*/
|
|
736
|
-
convertResponseToUint8Array(text) {
|
|
737
|
-
const array = new Uint8Array(text.length);
|
|
738
|
-
for (let i = 0; i < text.length; i++) {
|
|
739
|
-
array[i] = text.charCodeAt(i) & 255;
|
|
740
|
-
}
|
|
741
|
-
return array;
|
|
742
|
-
}
|
|
743
554
|
/**
|
|
744
555
|
* {@inheritDoc @embedpdf/models!PdfEngine.openDocument}
|
|
745
556
|
*
|
|
@@ -805,89 +616,6 @@ class PdfiumEngine {
|
|
|
805
616
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
|
|
806
617
|
return PdfTaskHelper.resolve(pdfDoc);
|
|
807
618
|
}
|
|
808
|
-
openDocumentFromLoader(fileLoader, password = "") {
|
|
809
|
-
const { fileLength, callback, ...file } = fileLoader;
|
|
810
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentFromLoader", file, password);
|
|
811
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, "Begin", file.id);
|
|
812
|
-
const readBlock = (_pThis, offset, pBuf, length) => {
|
|
813
|
-
try {
|
|
814
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "readBlock", offset, length, pBuf);
|
|
815
|
-
if (offset < 0 || offset >= fileLength) {
|
|
816
|
-
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "Offset out of bounds:", offset);
|
|
817
|
-
return 0;
|
|
818
|
-
}
|
|
819
|
-
const data = callback(offset, length);
|
|
820
|
-
const dest = new Uint8Array(this.pdfiumModule.pdfium.HEAPU8.buffer, pBuf, data.length);
|
|
821
|
-
dest.set(data);
|
|
822
|
-
return data.length;
|
|
823
|
-
} catch (error) {
|
|
824
|
-
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "ReadBlock error:", error);
|
|
825
|
-
return 0;
|
|
826
|
-
}
|
|
827
|
-
};
|
|
828
|
-
const callbackPtr = this.pdfiumModule.pdfium.addFunction(readBlock, "iiiii");
|
|
829
|
-
const structSize = 12;
|
|
830
|
-
const fileAccessPtr = this.memoryManager.malloc(structSize);
|
|
831
|
-
this.pdfiumModule.pdfium.setValue(fileAccessPtr, fileLength, "i32");
|
|
832
|
-
this.pdfiumModule.pdfium.setValue(fileAccessPtr + 4, callbackPtr, "i32");
|
|
833
|
-
this.pdfiumModule.pdfium.setValue(fileAccessPtr + 8, 0, "i32");
|
|
834
|
-
const docPtr = this.pdfiumModule.FPDF_LoadCustomDocument(fileAccessPtr, password);
|
|
835
|
-
if (!docPtr) {
|
|
836
|
-
const lastError = this.pdfiumModule.FPDF_GetLastError();
|
|
837
|
-
this.logger.error(
|
|
838
|
-
LOG_SOURCE,
|
|
839
|
-
LOG_CATEGORY,
|
|
840
|
-
`FPDF_LoadCustomDocument failed with ${lastError}`
|
|
841
|
-
);
|
|
842
|
-
this.memoryManager.free(fileAccessPtr);
|
|
843
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, "End", file.id);
|
|
844
|
-
return PdfTaskHelper.reject({
|
|
845
|
-
code: lastError,
|
|
846
|
-
message: `FPDF_LoadCustomDocument failed`
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
const pageCount = this.pdfiumModule.FPDF_GetPageCount(docPtr);
|
|
850
|
-
const pages = [];
|
|
851
|
-
const sizePtr = this.memoryManager.malloc(8);
|
|
852
|
-
for (let index = 0; index < pageCount; index++) {
|
|
853
|
-
const result = this.pdfiumModule.FPDF_GetPageSizeByIndexF(docPtr, index, sizePtr);
|
|
854
|
-
if (!result) {
|
|
855
|
-
const lastError = this.pdfiumModule.FPDF_GetLastError();
|
|
856
|
-
this.logger.error(
|
|
857
|
-
LOG_SOURCE,
|
|
858
|
-
LOG_CATEGORY,
|
|
859
|
-
`FPDF_GetPageSizeByIndexF failed with ${lastError}`
|
|
860
|
-
);
|
|
861
|
-
this.memoryManager.free(sizePtr);
|
|
862
|
-
this.pdfiumModule.FPDF_CloseDocument(docPtr);
|
|
863
|
-
this.memoryManager.free(fileAccessPtr);
|
|
864
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, "End", file.id);
|
|
865
|
-
return PdfTaskHelper.reject({
|
|
866
|
-
code: lastError,
|
|
867
|
-
message: `FPDF_GetPageSizeByIndexF failed`
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index);
|
|
871
|
-
const page = {
|
|
872
|
-
index,
|
|
873
|
-
size: {
|
|
874
|
-
width: this.pdfiumModule.pdfium.getValue(sizePtr, "float"),
|
|
875
|
-
height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, "float")
|
|
876
|
-
},
|
|
877
|
-
rotation
|
|
878
|
-
};
|
|
879
|
-
pages.push(page);
|
|
880
|
-
}
|
|
881
|
-
this.memoryManager.free(sizePtr);
|
|
882
|
-
const pdfDoc = {
|
|
883
|
-
id: file.id,
|
|
884
|
-
pageCount,
|
|
885
|
-
pages
|
|
886
|
-
};
|
|
887
|
-
this.cache.setDocument(file.id, fileAccessPtr, docPtr);
|
|
888
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, "End", file.id);
|
|
889
|
-
return PdfTaskHelper.resolve(pdfDoc);
|
|
890
|
-
}
|
|
891
619
|
/**
|
|
892
620
|
* {@inheritDoc @embedpdf/models!PdfEngine.getMetadata}
|
|
893
621
|
*
|
|
@@ -1187,7 +915,7 @@ class PdfiumEngine {
|
|
|
1187
915
|
*
|
|
1188
916
|
* @public
|
|
1189
917
|
*/
|
|
1190
|
-
|
|
918
|
+
renderPageRaw(doc, page, options) {
|
|
1191
919
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderPage", doc, page, options);
|
|
1192
920
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, "Begin", `${doc.id}-${page.index}`);
|
|
1193
921
|
const rect = { origin: { x: 0, y: 0 }, size: page.size };
|
|
@@ -1213,56 +941,6 @@ class PdfiumEngine {
|
|
|
1213
941
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPageRect`, "End", `${doc.id}-${page.index}`);
|
|
1214
942
|
return task;
|
|
1215
943
|
}
|
|
1216
|
-
/**
|
|
1217
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getAllAnnotations}
|
|
1218
|
-
*
|
|
1219
|
-
* @public
|
|
1220
|
-
*/
|
|
1221
|
-
getAllAnnotations(doc) {
|
|
1222
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getAllAnnotations-with-progress", doc);
|
|
1223
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "Begin", doc.id);
|
|
1224
|
-
const task = PdfTaskHelper.create();
|
|
1225
|
-
let cancelled = false;
|
|
1226
|
-
task.wait(ignore, (err) => {
|
|
1227
|
-
if (err.type === "abort") cancelled = true;
|
|
1228
|
-
});
|
|
1229
|
-
const ctx = this.cache.getContext(doc.id);
|
|
1230
|
-
if (!ctx) {
|
|
1231
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "End", doc.id);
|
|
1232
|
-
task.reject({ code: PdfErrorCode.DocNotOpen, message: "document does not open" });
|
|
1233
|
-
return task;
|
|
1234
|
-
}
|
|
1235
|
-
const CHUNK_SIZE = 100;
|
|
1236
|
-
const out = {};
|
|
1237
|
-
const processChunk = (startIdx) => {
|
|
1238
|
-
if (cancelled) return;
|
|
1239
|
-
const endIdx = Math.min(startIdx + CHUNK_SIZE, doc.pageCount);
|
|
1240
|
-
for (let pageIdx = startIdx; pageIdx < endIdx && !cancelled; ++pageIdx) {
|
|
1241
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "Begin", doc.id, pageIdx);
|
|
1242
|
-
const annots = this.readPageAnnotationsRaw(ctx, doc.pages[pageIdx]);
|
|
1243
|
-
out[pageIdx] = annots;
|
|
1244
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "End", doc.id, pageIdx);
|
|
1245
|
-
task.progress({ page: pageIdx, annotations: annots });
|
|
1246
|
-
}
|
|
1247
|
-
if (cancelled) return;
|
|
1248
|
-
if (endIdx >= doc.pageCount) {
|
|
1249
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "End", doc.id);
|
|
1250
|
-
task.resolve(out);
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
setTimeout(() => processChunk(endIdx), 0);
|
|
1254
|
-
};
|
|
1255
|
-
processChunk(0);
|
|
1256
|
-
return task;
|
|
1257
|
-
}
|
|
1258
|
-
readAllAnnotations(doc, ctx) {
|
|
1259
|
-
const annotationsByPage = {};
|
|
1260
|
-
for (let i = 0; i < doc.pageCount; i++) {
|
|
1261
|
-
const pageAnnotations = this.readPageAnnotations(ctx, doc.pages[i]);
|
|
1262
|
-
annotationsByPage[i] = pageAnnotations;
|
|
1263
|
-
}
|
|
1264
|
-
return annotationsByPage;
|
|
1265
|
-
}
|
|
1266
944
|
/**
|
|
1267
945
|
* {@inheritDoc @embedpdf/models!PdfEngine.getPageAnnotations}
|
|
1268
946
|
*
|
|
@@ -1688,7 +1366,7 @@ class PdfiumEngine {
|
|
|
1688
1366
|
*
|
|
1689
1367
|
* @public
|
|
1690
1368
|
*/
|
|
1691
|
-
|
|
1369
|
+
renderThumbnailRaw(doc, page, options) {
|
|
1692
1370
|
const { scaleFactor = 1, ...rest } = options ?? {};
|
|
1693
1371
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderThumbnail", doc, page, options);
|
|
1694
1372
|
this.logger.perf(
|
|
@@ -1712,7 +1390,7 @@ class PdfiumEngine {
|
|
|
1712
1390
|
message: "document does not open"
|
|
1713
1391
|
});
|
|
1714
1392
|
}
|
|
1715
|
-
const result = this.
|
|
1393
|
+
const result = this.renderPageRaw(doc, page, {
|
|
1716
1394
|
scaleFactor: Math.max(scaleFactor, 0.5),
|
|
1717
1395
|
...rest
|
|
1718
1396
|
});
|
|
@@ -3560,7 +3238,7 @@ class PdfiumEngine {
|
|
|
3560
3238
|
});
|
|
3561
3239
|
}
|
|
3562
3240
|
/**
|
|
3563
|
-
* Read page annotations
|
|
3241
|
+
* Read page annotations without loading the page (raw approach)
|
|
3564
3242
|
*
|
|
3565
3243
|
* @param ctx - document context
|
|
3566
3244
|
* @param page - page info
|
|
@@ -3584,6 +3262,48 @@ class PdfiumEngine {
|
|
|
3584
3262
|
}
|
|
3585
3263
|
return out;
|
|
3586
3264
|
}
|
|
3265
|
+
/**
|
|
3266
|
+
* Get page annotations (public API, returns Task)
|
|
3267
|
+
*
|
|
3268
|
+
* @param doc - pdf document
|
|
3269
|
+
* @param page - page info
|
|
3270
|
+
* @returns task with annotations on the pdf page
|
|
3271
|
+
*
|
|
3272
|
+
* @public
|
|
3273
|
+
*/
|
|
3274
|
+
getPageAnnotationsRaw(doc, page) {
|
|
3275
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getPageAnnotationsRaw", doc, page);
|
|
3276
|
+
this.logger.perf(
|
|
3277
|
+
LOG_SOURCE,
|
|
3278
|
+
LOG_CATEGORY,
|
|
3279
|
+
`GetPageAnnotationsRaw`,
|
|
3280
|
+
"Begin",
|
|
3281
|
+
`${doc.id}-${page.index}`
|
|
3282
|
+
);
|
|
3283
|
+
const ctx = this.cache.getContext(doc.id);
|
|
3284
|
+
if (!ctx) {
|
|
3285
|
+
return PdfTaskHelper.reject({
|
|
3286
|
+
code: PdfErrorCode.DocNotOpen,
|
|
3287
|
+
message: "document does not open"
|
|
3288
|
+
});
|
|
3289
|
+
}
|
|
3290
|
+
const out = this.readPageAnnotationsRaw(ctx, page);
|
|
3291
|
+
this.logger.perf(
|
|
3292
|
+
LOG_SOURCE,
|
|
3293
|
+
LOG_CATEGORY,
|
|
3294
|
+
`GetPageAnnotationsRaw`,
|
|
3295
|
+
"End",
|
|
3296
|
+
`${doc.id}-${page.index}`
|
|
3297
|
+
);
|
|
3298
|
+
this.logger.debug(
|
|
3299
|
+
LOG_SOURCE,
|
|
3300
|
+
LOG_CATEGORY,
|
|
3301
|
+
"getPageAnnotationsRaw",
|
|
3302
|
+
`${doc.id}-${page.index}`,
|
|
3303
|
+
out
|
|
3304
|
+
);
|
|
3305
|
+
return PdfTaskHelper.resolve(out);
|
|
3306
|
+
}
|
|
3587
3307
|
/**
|
|
3588
3308
|
* Read pdf annotation from pdf document
|
|
3589
3309
|
*
|
|
@@ -5145,11 +4865,15 @@ class PdfiumEngine {
|
|
|
5145
4865
|
break;
|
|
5146
4866
|
}
|
|
5147
4867
|
}
|
|
5148
|
-
const
|
|
4868
|
+
const imageDataLike = {
|
|
4869
|
+
data: array,
|
|
4870
|
+
width: bitmapWidth,
|
|
4871
|
+
height: bitmapHeight
|
|
4872
|
+
};
|
|
5149
4873
|
const matrix = this.readPdfPageObjectTransformMatrix(imageObjectPtr);
|
|
5150
4874
|
return {
|
|
5151
4875
|
type: PdfPageObjectType.IMAGE,
|
|
5152
|
-
imageData,
|
|
4876
|
+
imageData: imageDataLike,
|
|
5153
4877
|
matrix
|
|
5154
4878
|
};
|
|
5155
4879
|
}
|
|
@@ -5783,14 +5507,12 @@ class PdfiumEngine {
|
|
|
5783
5507
|
*
|
|
5784
5508
|
* @public
|
|
5785
5509
|
*/
|
|
5786
|
-
|
|
5510
|
+
renderPageAnnotationRaw(doc, page, annotation, options) {
|
|
5787
5511
|
const {
|
|
5788
5512
|
scaleFactor = 1,
|
|
5789
5513
|
rotation = Rotation.Degree0,
|
|
5790
5514
|
dpr = 1,
|
|
5791
|
-
mode = AppearanceMode.Normal
|
|
5792
|
-
imageType = "image/webp",
|
|
5793
|
-
imageQuality
|
|
5515
|
+
mode = AppearanceMode.Normal
|
|
5794
5516
|
} = options ?? {};
|
|
5795
5517
|
this.logger.debug(
|
|
5796
5518
|
LOG_SOURCE,
|
|
@@ -5893,97 +5615,18 @@ class PdfiumEngine {
|
|
|
5893
5615
|
message: "EPDF_RenderAnnotBitmap failed"
|
|
5894
5616
|
});
|
|
5895
5617
|
}
|
|
5896
|
-
const
|
|
5897
|
-
|
|
5898
|
-
()
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
);
|
|
5902
|
-
return {
|
|
5903
|
-
width: wDev,
|
|
5904
|
-
height: hDev,
|
|
5905
|
-
data: rgba
|
|
5906
|
-
};
|
|
5907
|
-
},
|
|
5908
|
-
imageType,
|
|
5909
|
-
imageQuality
|
|
5910
|
-
).then((out) => task.resolve(out)).catch((e) => {
|
|
5911
|
-
if (e instanceof OffscreenCanvasError) {
|
|
5912
|
-
try {
|
|
5913
|
-
const blob = this.encodeViaWasm(
|
|
5914
|
-
{ ptr: heapPtr, width: wDev, height: hDev, stride },
|
|
5915
|
-
{ type: imageType, quality: imageQuality }
|
|
5916
|
-
);
|
|
5917
|
-
task.resolve(blob);
|
|
5918
|
-
} catch (wasmError) {
|
|
5919
|
-
task.reject({ code: PdfErrorCode.Unknown, message: String(wasmError) });
|
|
5920
|
-
}
|
|
5921
|
-
} else {
|
|
5922
|
-
task.reject({ code: PdfErrorCode.Unknown, message: String(e) });
|
|
5923
|
-
}
|
|
5924
|
-
}).finally(dispose);
|
|
5925
|
-
return task;
|
|
5926
|
-
}
|
|
5927
|
-
encodeViaWasm(buf, opts) {
|
|
5928
|
-
const pdf = this.pdfiumModule.pdfium;
|
|
5929
|
-
const blobFrom = (outPtr, size, mime) => {
|
|
5930
|
-
const view = pdf.HEAPU8.subarray(outPtr, outPtr + size);
|
|
5931
|
-
const copy = new Uint8Array(view);
|
|
5932
|
-
this.memoryManager.free(outPtr);
|
|
5933
|
-
return new Blob([copy], { type: mime });
|
|
5618
|
+
const data = this.pdfiumModule.pdfium.HEAPU8.subarray(heapPtr, heapPtr + bytes);
|
|
5619
|
+
const imageDataLike = {
|
|
5620
|
+
data: new Uint8ClampedArray(data),
|
|
5621
|
+
width: wDev,
|
|
5622
|
+
height: hDev
|
|
5934
5623
|
};
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
switch (opts.type) {
|
|
5939
|
-
/*
|
|
5940
|
-
case 'image/webp': {
|
|
5941
|
-
const size = this.pdfiumModule.EPDF_WebP_EncodeRGBA(
|
|
5942
|
-
buf.ptr,
|
|
5943
|
-
buf.width,
|
|
5944
|
-
buf.height,
|
|
5945
|
-
buf.stride,
|
|
5946
|
-
webpQ,
|
|
5947
|
-
outPtrPtr,
|
|
5948
|
-
);
|
|
5949
|
-
const outPtr = pdf.getValue(outPtrPtr, 'i32');
|
|
5950
|
-
return blobFrom(outPtr, size, 'image/webp');
|
|
5951
|
-
}
|
|
5952
|
-
case 'image/jpeg': {
|
|
5953
|
-
const size = this.pdfiumModule.EPDF_JPEG_EncodeRGBA(
|
|
5954
|
-
buf.ptr,
|
|
5955
|
-
buf.width,
|
|
5956
|
-
buf.height,
|
|
5957
|
-
buf.stride,
|
|
5958
|
-
jpegQ,
|
|
5959
|
-
outPtrPtr,
|
|
5960
|
-
);
|
|
5961
|
-
const outPtr = pdf.getValue(outPtrPtr, 'i32');
|
|
5962
|
-
return blobFrom(outPtr, size, 'image/jpeg');
|
|
5963
|
-
}
|
|
5964
|
-
*/
|
|
5965
|
-
case "image/png":
|
|
5966
|
-
default: {
|
|
5967
|
-
const size = this.pdfiumModule.EPDF_PNG_EncodeRGBA(
|
|
5968
|
-
buf.ptr,
|
|
5969
|
-
buf.width,
|
|
5970
|
-
buf.height,
|
|
5971
|
-
buf.stride,
|
|
5972
|
-
pngLevel,
|
|
5973
|
-
outPtrPtr
|
|
5974
|
-
);
|
|
5975
|
-
const outPtr = pdf.getValue(outPtrPtr, "i32");
|
|
5976
|
-
return blobFrom(WasmPointer(outPtr), size, "image/png");
|
|
5977
|
-
}
|
|
5978
|
-
}
|
|
5979
|
-
} finally {
|
|
5980
|
-
this.memoryManager.free(outPtrPtr);
|
|
5981
|
-
}
|
|
5624
|
+
task.resolve(imageDataLike);
|
|
5625
|
+
this.memoryManager.free(heapPtr);
|
|
5626
|
+
return task;
|
|
5982
5627
|
}
|
|
5983
5628
|
renderRectEncoded(doc, page, rect, options) {
|
|
5984
5629
|
const task = new Task();
|
|
5985
|
-
const imageType = (options == null ? void 0 : options.imageType) ?? "image/webp";
|
|
5986
|
-
const quality = options == null ? void 0 : options.imageQuality;
|
|
5987
5630
|
const rotation = (options == null ? void 0 : options.rotation) ?? Rotation.Degree0;
|
|
5988
5631
|
const ctx = this.cache.getContext(doc.id);
|
|
5989
5632
|
if (!ctx) {
|
|
@@ -6051,39 +5694,43 @@ class PdfiumEngine {
|
|
|
6051
5694
|
this.memoryManager.free(mPtr);
|
|
6052
5695
|
this.memoryManager.free(clipPtr);
|
|
6053
5696
|
}
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
5697
|
+
this.logger.perf(
|
|
5698
|
+
LOG_SOURCE,
|
|
5699
|
+
LOG_CATEGORY,
|
|
5700
|
+
`RenderRectEncodedData`,
|
|
5701
|
+
"Begin",
|
|
5702
|
+
`${doc.id}-${page.index}`
|
|
5703
|
+
);
|
|
5704
|
+
const data = this.pdfiumModule.pdfium.HEAPU8.subarray(heapPtr, heapPtr + bytes);
|
|
5705
|
+
this.logger.perf(
|
|
5706
|
+
LOG_SOURCE,
|
|
5707
|
+
LOG_CATEGORY,
|
|
5708
|
+
`RenderRectEncodedData`,
|
|
5709
|
+
"End",
|
|
5710
|
+
`${doc.id}-${page.index}`
|
|
5711
|
+
);
|
|
5712
|
+
this.logger.perf(
|
|
5713
|
+
LOG_SOURCE,
|
|
5714
|
+
LOG_CATEGORY,
|
|
5715
|
+
`RenderRectEncodedImageData`,
|
|
5716
|
+
"Begin",
|
|
5717
|
+
`${doc.id}-${page.index}`
|
|
5718
|
+
);
|
|
5719
|
+
const imageDataLike = {
|
|
5720
|
+
data: new Uint8ClampedArray(data),
|
|
5721
|
+
width: wDev,
|
|
5722
|
+
height: hDev
|
|
6057
5723
|
};
|
|
6058
|
-
this.
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
imageType,
|
|
6069
|
-
quality
|
|
6070
|
-
).then((out) => task.resolve(out)).catch((e) => {
|
|
6071
|
-
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "Error", e);
|
|
6072
|
-
if (e instanceof OffscreenCanvasError) {
|
|
6073
|
-
this.logger.info(LOG_SOURCE, LOG_CATEGORY, "Fallback to WASM encoding");
|
|
6074
|
-
try {
|
|
6075
|
-
const blob = this.encodeViaWasm(
|
|
6076
|
-
{ ptr: heapPtr, width: wDev, height: hDev, stride },
|
|
6077
|
-
{ type: imageType, quality }
|
|
6078
|
-
);
|
|
6079
|
-
task.resolve(blob);
|
|
6080
|
-
} catch (wasmError) {
|
|
6081
|
-
task.reject({ code: PdfErrorCode.Unknown, message: String(wasmError) });
|
|
6082
|
-
}
|
|
6083
|
-
} else {
|
|
6084
|
-
task.reject({ code: PdfErrorCode.Unknown, message: String(e) });
|
|
6085
|
-
}
|
|
6086
|
-
}).finally(dispose);
|
|
5724
|
+
this.logger.perf(
|
|
5725
|
+
LOG_SOURCE,
|
|
5726
|
+
LOG_CATEGORY,
|
|
5727
|
+
`RenderRectEncodedImageData`,
|
|
5728
|
+
"End",
|
|
5729
|
+
`${doc.id}-${page.index}`
|
|
5730
|
+
);
|
|
5731
|
+
task.resolve(imageDataLike);
|
|
5732
|
+
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
5733
|
+
this.memoryManager.free(heapPtr);
|
|
6087
5734
|
return task;
|
|
6088
5735
|
}
|
|
6089
5736
|
/**
|
|
@@ -6671,75 +6318,110 @@ class PdfiumEngine {
|
|
|
6671
6318
|
*
|
|
6672
6319
|
* @public
|
|
6673
6320
|
*/
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
this.logger.
|
|
6677
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchAllPages", "Begin", doc.id);
|
|
6321
|
+
searchInPage(doc, page, keyword, flags) {
|
|
6322
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "searchInPage", doc, page, keyword, flags);
|
|
6323
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SearchInPage`, "Begin", `${doc.id}-${page.index}`);
|
|
6678
6324
|
const ctx = this.cache.getContext(doc.id);
|
|
6679
6325
|
if (!ctx) {
|
|
6680
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY,
|
|
6681
|
-
return PdfTaskHelper.
|
|
6682
|
-
|
|
6683
|
-
|
|
6326
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, "End", doc.id);
|
|
6327
|
+
return PdfTaskHelper.reject({
|
|
6328
|
+
code: PdfErrorCode.DocNotOpen,
|
|
6329
|
+
message: "Document is not open"
|
|
6684
6330
|
});
|
|
6685
6331
|
}
|
|
6686
6332
|
const length = 2 * (keyword.length + 1);
|
|
6687
6333
|
const keywordPtr = this.memoryManager.malloc(length);
|
|
6688
6334
|
this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
()
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
task.reject({
|
|
6715
|
-
code: PdfErrorCode.Unknown,
|
|
6716
|
-
message: `Error searching document: ${e}`
|
|
6717
|
-
});
|
|
6718
|
-
}
|
|
6335
|
+
try {
|
|
6336
|
+
const results = this.searchAllInPage(ctx, page, keywordPtr, flags);
|
|
6337
|
+
return PdfTaskHelper.resolve(results);
|
|
6338
|
+
} finally {
|
|
6339
|
+
this.memoryManager.free(keywordPtr);
|
|
6340
|
+
}
|
|
6341
|
+
}
|
|
6342
|
+
/**
|
|
6343
|
+
* Get annotations for multiple pages in a single batch.
|
|
6344
|
+
* Emits progress per page for streaming updates.
|
|
6345
|
+
*
|
|
6346
|
+
* @param doc - PDF document
|
|
6347
|
+
* @param pages - Array of pages to process
|
|
6348
|
+
* @returns Task with results keyed by page index, with per-page progress
|
|
6349
|
+
*
|
|
6350
|
+
* @public
|
|
6351
|
+
*/
|
|
6352
|
+
getAnnotationsBatch(doc, pages) {
|
|
6353
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getAnnotationsBatch", doc.id, pages.length);
|
|
6354
|
+
const task = new Task();
|
|
6355
|
+
queueMicrotask(() => {
|
|
6356
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAnnotationsBatch", "Begin", doc.id);
|
|
6357
|
+
const ctx = this.cache.getContext(doc.id);
|
|
6358
|
+
if (!ctx) {
|
|
6359
|
+
task.reject({ code: PdfErrorCode.DocNotOpen, message: "Document is not open" });
|
|
6719
6360
|
return;
|
|
6720
6361
|
}
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6362
|
+
const results = {};
|
|
6363
|
+
const total = pages.length;
|
|
6364
|
+
for (let i = 0; i < pages.length; i++) {
|
|
6365
|
+
const page = pages[i];
|
|
6366
|
+
const annotations = this.readPageAnnotationsRaw(ctx, page);
|
|
6367
|
+
results[page.index] = annotations;
|
|
6368
|
+
task.progress({
|
|
6369
|
+
pageIndex: page.index,
|
|
6370
|
+
result: annotations,
|
|
6371
|
+
completed: i + 1,
|
|
6372
|
+
total
|
|
6373
|
+
});
|
|
6374
|
+
}
|
|
6375
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAnnotationsBatch", "End", doc.id);
|
|
6376
|
+
task.resolve(results);
|
|
6377
|
+
});
|
|
6378
|
+
return task;
|
|
6379
|
+
}
|
|
6380
|
+
/**
|
|
6381
|
+
* Search across multiple pages in a single batch.
|
|
6382
|
+
* Emits progress per page for streaming updates.
|
|
6383
|
+
*
|
|
6384
|
+
* @param doc - PDF document
|
|
6385
|
+
* @param pages - Array of pages to search
|
|
6386
|
+
* @param keyword - Search keyword
|
|
6387
|
+
* @param flags - Search flags
|
|
6388
|
+
* @returns Task with results keyed by page index, with per-page progress
|
|
6389
|
+
*
|
|
6390
|
+
* @public
|
|
6391
|
+
*/
|
|
6392
|
+
searchBatch(doc, pages, keyword, flags) {
|
|
6393
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "searchBatch", doc.id, pages.length, keyword);
|
|
6394
|
+
const task = new Task();
|
|
6395
|
+
queueMicrotask(() => {
|
|
6396
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchBatch", "Begin", doc.id);
|
|
6397
|
+
const ctx = this.cache.getContext(doc.id);
|
|
6398
|
+
if (!ctx) {
|
|
6399
|
+
task.reject({ code: PdfErrorCode.DocNotOpen, message: "Document is not open" });
|
|
6726
6400
|
return;
|
|
6727
6401
|
}
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6402
|
+
const length = 2 * (keyword.length + 1);
|
|
6403
|
+
const keywordPtr = this.memoryManager.malloc(length);
|
|
6404
|
+
this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);
|
|
6405
|
+
try {
|
|
6406
|
+
const results = {};
|
|
6407
|
+
const total = pages.length;
|
|
6408
|
+
for (let i = 0; i < pages.length; i++) {
|
|
6409
|
+
const page = pages[i];
|
|
6410
|
+
const pageResults = this.searchAllInPage(ctx, page, keywordPtr, flags);
|
|
6411
|
+
results[page.index] = pageResults;
|
|
6412
|
+
task.progress({
|
|
6413
|
+
pageIndex: page.index,
|
|
6414
|
+
result: pageResults,
|
|
6415
|
+
completed: i + 1,
|
|
6416
|
+
total
|
|
6417
|
+
});
|
|
6740
6418
|
}
|
|
6419
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchBatch", "End", doc.id);
|
|
6420
|
+
task.resolve(results);
|
|
6421
|
+
} finally {
|
|
6422
|
+
this.memoryManager.free(keywordPtr);
|
|
6741
6423
|
}
|
|
6742
|
-
);
|
|
6424
|
+
});
|
|
6743
6425
|
return task;
|
|
6744
6426
|
}
|
|
6745
6427
|
/**
|
|
@@ -7078,16 +6760,25 @@ class PdfiumEngine {
|
|
|
7078
6760
|
}
|
|
7079
6761
|
}
|
|
7080
6762
|
}
|
|
6763
|
+
async function createPdfiumEngine(wasmUrl, options) {
|
|
6764
|
+
const response = await fetch(wasmUrl);
|
|
6765
|
+
const wasmBinary = await response.arrayBuffer();
|
|
6766
|
+
const wasmModule = await init({ wasmBinary });
|
|
6767
|
+
const native = new PdfiumNative(wasmModule, { logger: options == null ? void 0 : options.logger });
|
|
6768
|
+
return new PdfEngine(native, {
|
|
6769
|
+
imageConverter: browserImageDataToBlobConverter,
|
|
6770
|
+
logger: options == null ? void 0 : options.logger
|
|
6771
|
+
});
|
|
6772
|
+
}
|
|
7081
6773
|
export {
|
|
7082
6774
|
BitmapFormat as B,
|
|
7083
|
-
OffscreenCanvasError as O,
|
|
7084
6775
|
PdfiumErrorCode as P,
|
|
7085
6776
|
RenderFlag as R,
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
6777
|
+
PdfiumNative as a,
|
|
6778
|
+
readArrayBuffer as b,
|
|
6779
|
+
createPdfiumEngine as c,
|
|
7089
6780
|
computeFormDrawParams as d,
|
|
7090
6781
|
isValidCustomKey as i,
|
|
7091
6782
|
readString as r
|
|
7092
6783
|
};
|
|
7093
|
-
//# sourceMappingURL=engine-
|
|
6784
|
+
//# sourceMappingURL=direct-engine-DuLFAbiv.js.map
|