@embedpdf/engines 1.0.17 → 1.0.19
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/dist/engine-CkrTs7st.cjs +2 -0
- package/dist/engine-CkrTs7st.cjs.map +1 -0
- package/dist/{engine-uSZXjmb5.js → engine-DMU8HkGx.js} +162 -154
- package/dist/engine-DMU8HkGx.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -37
- package/dist/index.js.map +1 -1
- package/dist/lib/converters/index.cjs +1 -1
- package/dist/lib/converters/index.cjs.map +1 -1
- package/dist/lib/converters/index.d.ts +4 -4
- package/dist/lib/converters/index.js +11 -2
- package/dist/lib/converters/index.js.map +1 -1
- package/dist/lib/pdfium/engine.d.ts +49 -38
- package/dist/lib/pdfium/index.cjs +1 -1
- package/dist/lib/pdfium/index.js +2 -2
- package/dist/lib/pdfium/runner.d.ts +2 -1
- 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.js +2 -2
- 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.js +7 -2
- package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/webworker/engine.cjs +1 -1
- package/dist/lib/webworker/engine.cjs.map +1 -1
- package/dist/lib/webworker/engine.d.ts +18 -18
- package/dist/lib/webworker/engine.js +43 -117
- package/dist/lib/webworker/engine.js.map +1 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.js +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +1 -1
- package/dist/runner-BPhmukiN.cjs +2 -0
- package/dist/runner-BPhmukiN.cjs.map +1 -0
- package/dist/{runner-BOJ4naYI.js → runner-TzQFlVIQ.js} +10 -10
- package/dist/runner-TzQFlVIQ.js.map +1 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +3 -3
- package/dist/engine-Bcr-xNy6.cjs +0 -2
- package/dist/engine-Bcr-xNy6.cjs.map +0 -1
- package/dist/engine-uSZXjmb5.js.map +0 -1
- package/dist/runner-BOJ4naYI.js.map +0 -1
- package/dist/runner-C64KrEhP.cjs +0 -2
- package/dist/runner-C64KrEhP.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NoopLogger, PdfTaskHelper, PdfErrorCode,
|
|
1
|
+
import { NoopLogger, PdfTaskHelper, PdfErrorCode, Task, ignore, isUuidV4, uuidV4, PdfAnnotationSubtype, Rotation, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, pdfDateToDate, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, toIntRect, transformRect, makeMatrix, toIntSize, transformSize, PdfActionType, PdfZoomMode, MatchFlag } from "@embedpdf/models";
|
|
2
2
|
function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
|
|
3
3
|
let buffer = wasmModule.wasmExports.malloc(defaultLength);
|
|
4
4
|
for (let i = 0; i < defaultLength; i++) {
|
|
@@ -242,7 +242,8 @@ const browserImageDataToBlobConverter = (pdfImageData, imageType = "image/webp")
|
|
|
242
242
|
"OffscreenCanvas is not available in this environment. This converter is intended for browser use only. Please use createNodeImageDataToBlobConverter() or createNodeCanvasImageDataToBlobConverter() for Node.js."
|
|
243
243
|
);
|
|
244
244
|
}
|
|
245
|
-
const
|
|
245
|
+
const rgba = new Uint8ClampedArray(pdfImageData.data);
|
|
246
|
+
const imageData = new ImageData(rgba, pdfImageData.width, pdfImageData.height);
|
|
246
247
|
const off = new OffscreenCanvas(imageData.width, imageData.height);
|
|
247
248
|
off.getContext("2d").putImageData(imageData, 0, 0);
|
|
248
249
|
return off.convertToBlob({ type: imageType });
|
|
@@ -254,11 +255,15 @@ class PdfiumEngine {
|
|
|
254
255
|
* @param logger - logger instance
|
|
255
256
|
* @param imageDataToBlobConverter - function to convert ImageData to Blob
|
|
256
257
|
*/
|
|
257
|
-
constructor(pdfiumModule,
|
|
258
|
+
constructor(pdfiumModule, options = {}) {
|
|
258
259
|
this.pdfiumModule = pdfiumModule;
|
|
260
|
+
const {
|
|
261
|
+
logger = new NoopLogger(),
|
|
262
|
+
imageDataConverter = browserImageDataToBlobConverter
|
|
263
|
+
} = options;
|
|
264
|
+
this.cache = new PdfCache(this.pdfiumModule);
|
|
259
265
|
this.logger = logger;
|
|
260
266
|
this.imageDataConverter = imageDataConverter;
|
|
261
|
-
this.cache = new PdfCache(this.pdfiumModule);
|
|
262
267
|
}
|
|
263
268
|
/**
|
|
264
269
|
* {@inheritDoc @embedpdf/models!PdfEngine.initialize}
|
|
@@ -296,47 +301,11 @@ class PdfiumEngine {
|
|
|
296
301
|
const task = PdfTaskHelper.create();
|
|
297
302
|
(async () => {
|
|
298
303
|
try {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
);
|
|
305
|
-
} else if (mode === "range-request") {
|
|
306
|
-
const openDocumentWithRangeRequestTask = await this.openDocumentWithRangeRequest(
|
|
307
|
-
file,
|
|
308
|
-
password
|
|
309
|
-
);
|
|
310
|
-
openDocumentWithRangeRequestTask.wait(
|
|
311
|
-
(doc) => task.resolve(doc),
|
|
312
|
-
(err) => task.reject(err.reason)
|
|
313
|
-
);
|
|
314
|
-
} else {
|
|
315
|
-
const { supportsRanges, fileLength, content } = await this.checkRangeSupport(file.url);
|
|
316
|
-
if (supportsRanges) {
|
|
317
|
-
const openDocumentWithRangeRequestTask = await this.openDocumentWithRangeRequest(
|
|
318
|
-
file,
|
|
319
|
-
password,
|
|
320
|
-
fileLength
|
|
321
|
-
);
|
|
322
|
-
openDocumentWithRangeRequestTask.wait(
|
|
323
|
-
(doc) => task.resolve(doc),
|
|
324
|
-
(err) => task.reject(err.reason)
|
|
325
|
-
);
|
|
326
|
-
} else if (content) {
|
|
327
|
-
const pdfFile = { id: file.id, content };
|
|
328
|
-
this.openDocumentFromBuffer(pdfFile, password).wait(
|
|
329
|
-
(doc) => task.resolve(doc),
|
|
330
|
-
(err) => task.reject(err.reason)
|
|
331
|
-
);
|
|
332
|
-
} else {
|
|
333
|
-
const fetchFullTask = await this.fetchFullAndOpen(file, password);
|
|
334
|
-
fetchFullTask.wait(
|
|
335
|
-
(doc) => task.resolve(doc),
|
|
336
|
-
(err) => task.reject(err.reason)
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
304
|
+
const fetchFullTask = await this.fetchFullAndOpen(file, password);
|
|
305
|
+
fetchFullTask.wait(
|
|
306
|
+
(doc) => task.resolve(doc),
|
|
307
|
+
(err) => task.reject(err.reason)
|
|
308
|
+
);
|
|
340
309
|
} catch (err) {
|
|
341
310
|
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "openDocumentUrl error", err);
|
|
342
311
|
task.reject({
|
|
@@ -400,7 +369,7 @@ class PdfiumEngine {
|
|
|
400
369
|
id: file.id,
|
|
401
370
|
content: arrayBuf
|
|
402
371
|
};
|
|
403
|
-
return this.
|
|
372
|
+
return this.openDocumentBuffer(pdfFile, { password });
|
|
404
373
|
}
|
|
405
374
|
/**
|
|
406
375
|
* Use your synchronous partial-loading approach:
|
|
@@ -463,19 +432,19 @@ class PdfiumEngine {
|
|
|
463
432
|
*
|
|
464
433
|
* @public
|
|
465
434
|
*/
|
|
466
|
-
|
|
467
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "
|
|
468
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `
|
|
435
|
+
openDocumentBuffer(file, options) {
|
|
436
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentBuffer", file, options);
|
|
437
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "Begin", file.id);
|
|
469
438
|
const array = new Uint8Array(file.content);
|
|
470
439
|
const length = array.length;
|
|
471
440
|
const filePtr = this.malloc(length);
|
|
472
441
|
this.pdfiumModule.pdfium.HEAPU8.set(array, filePtr);
|
|
473
|
-
const docPtr = this.pdfiumModule.FPDF_LoadMemDocument(filePtr, length, password);
|
|
442
|
+
const docPtr = this.pdfiumModule.FPDF_LoadMemDocument(filePtr, length, (options == null ? void 0 : options.password) ?? "");
|
|
474
443
|
if (!docPtr) {
|
|
475
444
|
const lastError = this.pdfiumModule.FPDF_GetLastError();
|
|
476
445
|
this.logger.error(LOG_SOURCE, LOG_CATEGORY, `FPDF_LoadMemDocument failed with ${lastError}`);
|
|
477
446
|
this.free(filePtr);
|
|
478
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `
|
|
447
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
|
|
479
448
|
return PdfTaskHelper.reject({
|
|
480
449
|
code: lastError,
|
|
481
450
|
message: `FPDF_LoadMemDocument failed`
|
|
@@ -496,7 +465,7 @@ class PdfiumEngine {
|
|
|
496
465
|
this.free(sizePtr);
|
|
497
466
|
this.pdfiumModule.FPDF_CloseDocument(docPtr);
|
|
498
467
|
this.free(filePtr);
|
|
499
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `
|
|
468
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
|
|
500
469
|
return PdfTaskHelper.reject({
|
|
501
470
|
code: lastError,
|
|
502
471
|
message: `FPDF_GetPageSizeByIndexF failed`
|
|
@@ -518,14 +487,9 @@ class PdfiumEngine {
|
|
|
518
487
|
pages
|
|
519
488
|
};
|
|
520
489
|
this.cache.setDocument(file.id, filePtr, docPtr);
|
|
521
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `
|
|
490
|
+
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
|
|
522
491
|
return PdfTaskHelper.resolve(pdfDoc);
|
|
523
492
|
}
|
|
524
|
-
/**
|
|
525
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.openDocumentFromLoader}
|
|
526
|
-
*
|
|
527
|
-
* @public
|
|
528
|
-
*/
|
|
529
493
|
openDocumentFromLoader(fileLoader, password = "") {
|
|
530
494
|
const { fileLength, callback, ...file } = fileLoader;
|
|
531
495
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentFromLoader", file, password);
|
|
@@ -761,19 +725,10 @@ class PdfiumEngine {
|
|
|
761
725
|
*
|
|
762
726
|
* @public
|
|
763
727
|
*/
|
|
764
|
-
renderPage(doc, page,
|
|
728
|
+
renderPage(doc, page, options) {
|
|
729
|
+
const { imageType = "image/webp" } = options ?? {};
|
|
765
730
|
const task = new Task();
|
|
766
|
-
this.logger.debug(
|
|
767
|
-
LOG_SOURCE,
|
|
768
|
-
LOG_CATEGORY,
|
|
769
|
-
"renderPage",
|
|
770
|
-
doc,
|
|
771
|
-
page,
|
|
772
|
-
scaleFactor,
|
|
773
|
-
rotation,
|
|
774
|
-
dpr,
|
|
775
|
-
options
|
|
776
|
-
);
|
|
731
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderPage", doc, page, options);
|
|
777
732
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, "Begin", `${doc.id}-${page.index}`);
|
|
778
733
|
const ctx = this.cache.getContext(doc.id);
|
|
779
734
|
if (!ctx) {
|
|
@@ -790,9 +745,6 @@ class PdfiumEngine {
|
|
|
790
745
|
origin: { x: 0, y: 0 },
|
|
791
746
|
size: page.size
|
|
792
747
|
},
|
|
793
|
-
scaleFactor,
|
|
794
|
-
rotation,
|
|
795
|
-
dpr,
|
|
796
748
|
options
|
|
797
749
|
);
|
|
798
750
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, "End", `${doc.id}-${page.index}`);
|
|
@@ -804,20 +756,10 @@ class PdfiumEngine {
|
|
|
804
756
|
*
|
|
805
757
|
* @public
|
|
806
758
|
*/
|
|
807
|
-
renderPageRect(doc, page,
|
|
759
|
+
renderPageRect(doc, page, rect, options) {
|
|
760
|
+
const { imageType = "image/webp" } = options ?? {};
|
|
808
761
|
const task = new Task();
|
|
809
|
-
this.logger.debug(
|
|
810
|
-
LOG_SOURCE,
|
|
811
|
-
LOG_CATEGORY,
|
|
812
|
-
"renderPageRect",
|
|
813
|
-
doc,
|
|
814
|
-
page,
|
|
815
|
-
scaleFactor,
|
|
816
|
-
rotation,
|
|
817
|
-
dpr,
|
|
818
|
-
rect,
|
|
819
|
-
options
|
|
820
|
-
);
|
|
762
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderPageRect", doc, page, rect, options);
|
|
821
763
|
this.logger.perf(
|
|
822
764
|
LOG_SOURCE,
|
|
823
765
|
LOG_CATEGORY,
|
|
@@ -839,15 +781,7 @@ class PdfiumEngine {
|
|
|
839
781
|
message: "document does not open"
|
|
840
782
|
});
|
|
841
783
|
}
|
|
842
|
-
const imageData = this.renderPageRectToImageData(
|
|
843
|
-
ctx,
|
|
844
|
-
page,
|
|
845
|
-
rect,
|
|
846
|
-
scaleFactor,
|
|
847
|
-
rotation,
|
|
848
|
-
dpr,
|
|
849
|
-
options
|
|
850
|
-
);
|
|
784
|
+
const imageData = this.renderPageRectToImageData(ctx, page, rect, options);
|
|
851
785
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPageRect`, "End", `${doc.id}-${page.index}`);
|
|
852
786
|
this.imageDataConverter(imageData, imageType).then((blob) => task.resolve(blob));
|
|
853
787
|
return task;
|
|
@@ -991,6 +925,9 @@ class PdfiumEngine {
|
|
|
991
925
|
message: "can not create annotation with specified type"
|
|
992
926
|
});
|
|
993
927
|
}
|
|
928
|
+
if (!isUuidV4(annotation.id)) {
|
|
929
|
+
annotation.id = uuidV4();
|
|
930
|
+
}
|
|
994
931
|
if (!this.setAnnotString(annotationPtr, "NM", annotation.id)) {
|
|
995
932
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);
|
|
996
933
|
pageCtx.release();
|
|
@@ -1074,7 +1011,6 @@ class PdfiumEngine {
|
|
|
1074
1011
|
this.pdfiumModule.EPDFAnnot_GenerateAppearance(annotationPtr);
|
|
1075
1012
|
}
|
|
1076
1013
|
this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
|
|
1077
|
-
const annotId = this.pdfiumModule.FPDFPage_GetAnnotIndex(pageCtx.pagePtr, annotationPtr);
|
|
1078
1014
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);
|
|
1079
1015
|
pageCtx.release();
|
|
1080
1016
|
this.logger.perf(
|
|
@@ -1084,10 +1020,7 @@ class PdfiumEngine {
|
|
|
1084
1020
|
"End",
|
|
1085
1021
|
`${doc.id}-${page.index}`
|
|
1086
1022
|
);
|
|
1087
|
-
return
|
|
1088
|
-
code: PdfErrorCode.CantCreateAnnot,
|
|
1089
|
-
message: "annotation created but index could not be determined"
|
|
1090
|
-
});
|
|
1023
|
+
return PdfTaskHelper.resolve(annotation.id);
|
|
1091
1024
|
}
|
|
1092
1025
|
/**
|
|
1093
1026
|
* Update an existing page annotation in-place
|
|
@@ -1286,16 +1219,8 @@ class PdfiumEngine {
|
|
|
1286
1219
|
*
|
|
1287
1220
|
* @public
|
|
1288
1221
|
*/
|
|
1289
|
-
getPageTextRects(doc, page
|
|
1290
|
-
this.logger.debug(
|
|
1291
|
-
LOG_SOURCE,
|
|
1292
|
-
LOG_CATEGORY,
|
|
1293
|
-
"getPageTextRects",
|
|
1294
|
-
doc,
|
|
1295
|
-
page,
|
|
1296
|
-
scaleFactor,
|
|
1297
|
-
rotation
|
|
1298
|
-
);
|
|
1222
|
+
getPageTextRects(doc, page) {
|
|
1223
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getPageTextRects", doc, page);
|
|
1299
1224
|
this.logger.perf(
|
|
1300
1225
|
LOG_SOURCE,
|
|
1301
1226
|
LOG_CATEGORY,
|
|
@@ -1336,17 +1261,9 @@ class PdfiumEngine {
|
|
|
1336
1261
|
*
|
|
1337
1262
|
* @public
|
|
1338
1263
|
*/
|
|
1339
|
-
renderThumbnail(doc, page,
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
LOG_CATEGORY,
|
|
1343
|
-
"renderThumbnail",
|
|
1344
|
-
doc,
|
|
1345
|
-
page,
|
|
1346
|
-
scaleFactor,
|
|
1347
|
-
rotation,
|
|
1348
|
-
dpr
|
|
1349
|
-
);
|
|
1264
|
+
renderThumbnail(doc, page, options) {
|
|
1265
|
+
const { scaleFactor = 1, rotation = Rotation.Degree0, dpr = 1 } = options ?? {};
|
|
1266
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderThumbnail", doc, page, options);
|
|
1350
1267
|
this.logger.perf(
|
|
1351
1268
|
LOG_SOURCE,
|
|
1352
1269
|
LOG_CATEGORY,
|
|
@@ -1368,8 +1285,10 @@ class PdfiumEngine {
|
|
|
1368
1285
|
message: "document does not open"
|
|
1369
1286
|
});
|
|
1370
1287
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1288
|
+
const result = this.renderPage(doc, page, {
|
|
1289
|
+
scaleFactor: Math.max(scaleFactor, 0.5),
|
|
1290
|
+
rotation,
|
|
1291
|
+
dpr,
|
|
1373
1292
|
withAnnotations: true
|
|
1374
1293
|
});
|
|
1375
1294
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderThumbnail`, "End", `${doc.id}-${page.index}`);
|
|
@@ -1632,7 +1551,8 @@ class PdfiumEngine {
|
|
|
1632
1551
|
*
|
|
1633
1552
|
* @public
|
|
1634
1553
|
*/
|
|
1635
|
-
flattenPage(doc, page,
|
|
1554
|
+
flattenPage(doc, page, options) {
|
|
1555
|
+
const { flag = PdfPageFlattenFlag.Display } = options ?? {};
|
|
1636
1556
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "flattenPage", doc, page, flag);
|
|
1637
1557
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `flattenPage`, "Begin", doc.id);
|
|
1638
1558
|
const ctx = this.cache.getContext(doc.id);
|
|
@@ -2973,12 +2893,9 @@ class PdfiumEngine {
|
|
|
2973
2893
|
}
|
|
2974
2894
|
/**
|
|
2975
2895
|
* Read page annotations
|
|
2896
|
+
*
|
|
2897
|
+
* @param ctx - document context
|
|
2976
2898
|
* @param page - page info
|
|
2977
|
-
* @param docPtr - pointer to pdf document
|
|
2978
|
-
* @param pagePtr - pointer to pdf page
|
|
2979
|
-
* @param textPagePtr - pointe to pdf text page
|
|
2980
|
-
* @param scaleFactor - scale factor
|
|
2981
|
-
* @param rotation - rotation angle
|
|
2982
2899
|
* @returns annotations on the pdf page
|
|
2983
2900
|
*
|
|
2984
2901
|
* @private
|
|
@@ -2996,6 +2913,15 @@ class PdfiumEngine {
|
|
|
2996
2913
|
return annotations;
|
|
2997
2914
|
});
|
|
2998
2915
|
}
|
|
2916
|
+
/**
|
|
2917
|
+
* Read page annotations
|
|
2918
|
+
*
|
|
2919
|
+
* @param ctx - document context
|
|
2920
|
+
* @param page - page info
|
|
2921
|
+
* @returns annotations on the pdf page
|
|
2922
|
+
*
|
|
2923
|
+
* @private
|
|
2924
|
+
*/
|
|
2999
2925
|
readPageAnnotationsRaw(ctx, page) {
|
|
3000
2926
|
const count = this.pdfiumModule.EPDFPage_GetAnnotCountRaw(ctx.docPtr, page.index);
|
|
3001
2927
|
if (count <= 0) return [];
|
|
@@ -3014,14 +2940,11 @@ class PdfiumEngine {
|
|
|
3014
2940
|
}
|
|
3015
2941
|
/**
|
|
3016
2942
|
* Read pdf annotation from pdf document
|
|
3017
|
-
*
|
|
3018
|
-
* @param docPtr - pointer to pdf document
|
|
3019
|
-
* @param
|
|
3020
|
-
* @param
|
|
3021
|
-
* @param
|
|
3022
|
-
* @param index - index of annotation in the pdf page
|
|
3023
|
-
* @param scaleFactor - factor of scalling
|
|
3024
|
-
* @param rotation - rotation angle
|
|
2943
|
+
*
|
|
2944
|
+
* @param docPtr - pointer to pdf document
|
|
2945
|
+
* @param page - page info
|
|
2946
|
+
* @param annotationPtr - pointer to pdf annotation
|
|
2947
|
+
* @param pageCtx - page context
|
|
3025
2948
|
* @returns pdf annotation
|
|
3026
2949
|
*
|
|
3027
2950
|
* @private
|
|
@@ -3673,6 +3596,86 @@ class PdfiumEngine {
|
|
|
3673
3596
|
this.free(buf);
|
|
3674
3597
|
return true;
|
|
3675
3598
|
}
|
|
3599
|
+
/**
|
|
3600
|
+
* Redact text that intersects ANY of the provided **quads** (device-space).
|
|
3601
|
+
* Returns `true` if the page changed. Always regenerates the page stream.
|
|
3602
|
+
*/
|
|
3603
|
+
redactTextInRects(doc, page, rects, options) {
|
|
3604
|
+
const { recurseForms = true, drawBlackBoxes = false } = options ?? {};
|
|
3605
|
+
this.logger.debug(
|
|
3606
|
+
"PDFiumEngine",
|
|
3607
|
+
"Engine",
|
|
3608
|
+
"redactTextInQuads",
|
|
3609
|
+
doc.id,
|
|
3610
|
+
page.index,
|
|
3611
|
+
rects.length
|
|
3612
|
+
);
|
|
3613
|
+
const label = "RedactTextInQuads";
|
|
3614
|
+
this.logger.perf("PDFiumEngine", "Engine", label, "Begin", `${doc.id}-${page.index}`);
|
|
3615
|
+
const ctx = this.cache.getContext(doc.id);
|
|
3616
|
+
if (!ctx) {
|
|
3617
|
+
this.logger.perf("PDFiumEngine", "Engine", label, "End", `${doc.id}-${page.index}`);
|
|
3618
|
+
return PdfTaskHelper.reject({
|
|
3619
|
+
code: PdfErrorCode.DocNotOpen,
|
|
3620
|
+
message: "document does not open"
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3623
|
+
const clean = (rects ?? []).filter(
|
|
3624
|
+
(r) => {
|
|
3625
|
+
var _a, _b, _c, _d;
|
|
3626
|
+
return r && Number.isFinite((_a = r.origin) == null ? void 0 : _a.x) && Number.isFinite((_b = r.origin) == null ? void 0 : _b.y) && Number.isFinite((_c = r.size) == null ? void 0 : _c.width) && Number.isFinite((_d = r.size) == null ? void 0 : _d.height) && r.size.width > 0 && r.size.height > 0;
|
|
3627
|
+
}
|
|
3628
|
+
);
|
|
3629
|
+
if (clean.length === 0) {
|
|
3630
|
+
this.logger.perf("PDFiumEngine", "Engine", label, "End", `${doc.id}-${page.index}`);
|
|
3631
|
+
return PdfTaskHelper.resolve(false);
|
|
3632
|
+
}
|
|
3633
|
+
const pageCtx = ctx.acquirePage(page.index);
|
|
3634
|
+
const { ptr, count } = this.allocFSQuadsBufferFromRects(page, clean);
|
|
3635
|
+
let ok = false;
|
|
3636
|
+
try {
|
|
3637
|
+
ok = !!this.pdfiumModule.EPDFText_RedactInQuads(
|
|
3638
|
+
pageCtx.pagePtr,
|
|
3639
|
+
ptr,
|
|
3640
|
+
count,
|
|
3641
|
+
recurseForms ? true : false,
|
|
3642
|
+
drawBlackBoxes ? true : false
|
|
3643
|
+
);
|
|
3644
|
+
} finally {
|
|
3645
|
+
this.free(ptr);
|
|
3646
|
+
}
|
|
3647
|
+
if (ok) {
|
|
3648
|
+
ok = !!this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
|
|
3649
|
+
}
|
|
3650
|
+
pageCtx.disposeImmediate();
|
|
3651
|
+
this.logger.perf("PDFiumEngine", "Engine", label, "End", `${doc.id}-${page.index}`);
|
|
3652
|
+
return PdfTaskHelper.resolve(!!ok);
|
|
3653
|
+
}
|
|
3654
|
+
/** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */
|
|
3655
|
+
allocFSQuadsBufferFromRects(page, rects) {
|
|
3656
|
+
const STRIDE = 32;
|
|
3657
|
+
const count = rects.length;
|
|
3658
|
+
const ptr = this.malloc(STRIDE * count);
|
|
3659
|
+
const pdf = this.pdfiumModule.pdfium;
|
|
3660
|
+
for (let i = 0; i < count; i++) {
|
|
3661
|
+
const r = rects[i];
|
|
3662
|
+
const q = rectToQuad(r);
|
|
3663
|
+
const p1 = this.convertDevicePointToPagePoint(page, q.p1);
|
|
3664
|
+
const p2 = this.convertDevicePointToPagePoint(page, q.p2);
|
|
3665
|
+
const p3 = this.convertDevicePointToPagePoint(page, q.p3);
|
|
3666
|
+
const p4 = this.convertDevicePointToPagePoint(page, q.p4);
|
|
3667
|
+
const base = ptr + i * STRIDE;
|
|
3668
|
+
pdf.setValue(base + 0, p1.x, "float");
|
|
3669
|
+
pdf.setValue(base + 4, p1.y, "float");
|
|
3670
|
+
pdf.setValue(base + 8, p2.x, "float");
|
|
3671
|
+
pdf.setValue(base + 12, p2.y, "float");
|
|
3672
|
+
pdf.setValue(base + 16, p4.x, "float");
|
|
3673
|
+
pdf.setValue(base + 20, p4.y, "float");
|
|
3674
|
+
pdf.setValue(base + 24, p3.x, "float");
|
|
3675
|
+
pdf.setValue(base + 28, p3.y, "float");
|
|
3676
|
+
}
|
|
3677
|
+
return { ptr, count };
|
|
3678
|
+
}
|
|
3676
3679
|
/**
|
|
3677
3680
|
* Read ink list from annotation
|
|
3678
3681
|
* @param page - logical page info object (`PdfPageObject`)
|
|
@@ -5062,24 +5065,27 @@ class PdfiumEngine {
|
|
|
5062
5065
|
*
|
|
5063
5066
|
* @public
|
|
5064
5067
|
*/
|
|
5065
|
-
|
|
5068
|
+
renderPageAnnotation(doc, page, annotation, options) {
|
|
5069
|
+
const {
|
|
5070
|
+
scaleFactor = 1,
|
|
5071
|
+
rotation = Rotation.Degree0,
|
|
5072
|
+
dpr = 1,
|
|
5073
|
+
mode = AppearanceMode.Normal,
|
|
5074
|
+
imageType = "image/webp"
|
|
5075
|
+
} = options ?? {};
|
|
5066
5076
|
this.logger.debug(
|
|
5067
5077
|
LOG_SOURCE,
|
|
5068
5078
|
LOG_CATEGORY,
|
|
5069
|
-
"
|
|
5079
|
+
"renderPageAnnotation",
|
|
5070
5080
|
doc,
|
|
5071
5081
|
page,
|
|
5072
5082
|
annotation,
|
|
5073
|
-
|
|
5074
|
-
rotation,
|
|
5075
|
-
dpr,
|
|
5076
|
-
mode,
|
|
5077
|
-
imageType
|
|
5083
|
+
options
|
|
5078
5084
|
);
|
|
5079
5085
|
this.logger.perf(
|
|
5080
5086
|
LOG_SOURCE,
|
|
5081
5087
|
LOG_CATEGORY,
|
|
5082
|
-
`
|
|
5088
|
+
`RenderPageAnnotation`,
|
|
5083
5089
|
"Begin",
|
|
5084
5090
|
`${doc.id}-${page.index}-${annotation.id}`
|
|
5085
5091
|
);
|
|
@@ -5089,7 +5095,7 @@ class PdfiumEngine {
|
|
|
5089
5095
|
this.logger.perf(
|
|
5090
5096
|
LOG_SOURCE,
|
|
5091
5097
|
LOG_CATEGORY,
|
|
5092
|
-
`
|
|
5098
|
+
`RenderPageAnnotation`,
|
|
5093
5099
|
"End",
|
|
5094
5100
|
`${doc.id}-${page.index}-${annotation.id}`
|
|
5095
5101
|
);
|
|
@@ -5105,7 +5111,7 @@ class PdfiumEngine {
|
|
|
5105
5111
|
this.logger.perf(
|
|
5106
5112
|
LOG_SOURCE,
|
|
5107
5113
|
LOG_CATEGORY,
|
|
5108
|
-
`
|
|
5114
|
+
`RenderPageAnnotation`,
|
|
5109
5115
|
"End",
|
|
5110
5116
|
`${doc.id}-${page.index}-${annotation.id}`
|
|
5111
5117
|
);
|
|
@@ -5159,7 +5165,7 @@ class PdfiumEngine {
|
|
|
5159
5165
|
this.logger.perf(
|
|
5160
5166
|
LOG_SOURCE,
|
|
5161
5167
|
LOG_CATEGORY,
|
|
5162
|
-
`
|
|
5168
|
+
`RenderPageAnnotation`,
|
|
5163
5169
|
"End",
|
|
5164
5170
|
`${doc.id}-${page.index}-${annotation.id}`
|
|
5165
5171
|
);
|
|
@@ -5181,7 +5187,7 @@ class PdfiumEngine {
|
|
|
5181
5187
|
this.logger.perf(
|
|
5182
5188
|
LOG_SOURCE,
|
|
5183
5189
|
LOG_CATEGORY,
|
|
5184
|
-
`
|
|
5190
|
+
`RenderPageAnnotation`,
|
|
5185
5191
|
"End",
|
|
5186
5192
|
`${doc.id}-${page.index}-${annotation.id}`
|
|
5187
5193
|
);
|
|
@@ -5200,7 +5206,8 @@ class PdfiumEngine {
|
|
|
5200
5206
|
*
|
|
5201
5207
|
* @private
|
|
5202
5208
|
*/
|
|
5203
|
-
renderPageRectToImageData(ctx, page, rect,
|
|
5209
|
+
renderPageRectToImageData(ctx, page, rect, options) {
|
|
5210
|
+
const { scaleFactor = 1, rotation = Rotation.Degree0, dpr = 1 } = options ?? {};
|
|
5204
5211
|
const format = 4;
|
|
5205
5212
|
const bytesPerPixel = 4;
|
|
5206
5213
|
const rectSize = toIntRect(transformRect(page.size, rect, rotation, scaleFactor * dpr));
|
|
@@ -5730,8 +5737,9 @@ class PdfiumEngine {
|
|
|
5730
5737
|
*
|
|
5731
5738
|
* @public
|
|
5732
5739
|
*/
|
|
5733
|
-
searchAllPages(doc, keyword,
|
|
5734
|
-
|
|
5740
|
+
searchAllPages(doc, keyword, options) {
|
|
5741
|
+
var _a;
|
|
5742
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "searchAllPages", doc, keyword, options);
|
|
5735
5743
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchAllPages", "Begin", doc.id);
|
|
5736
5744
|
const ctx = this.cache.getContext(doc.id);
|
|
5737
5745
|
if (!ctx) {
|
|
@@ -5744,7 +5752,7 @@ class PdfiumEngine {
|
|
|
5744
5752
|
const length = 2 * (keyword.length + 1);
|
|
5745
5753
|
const keywordPtr = this.malloc(length);
|
|
5746
5754
|
this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);
|
|
5747
|
-
const flag = flags.reduce((acc, f) => acc | f, MatchFlag.None);
|
|
5755
|
+
const flag = ((_a = options == null ? void 0 : options.flags) == null ? void 0 : _a.reduce((acc, f) => acc | f, MatchFlag.None)) ?? MatchFlag.None;
|
|
5748
5756
|
const task = PdfTaskHelper.create();
|
|
5749
5757
|
let cancelled = false;
|
|
5750
5758
|
task.wait(
|
|
@@ -5917,4 +5925,4 @@ export {
|
|
|
5917
5925
|
readArrayBuffer as c,
|
|
5918
5926
|
readString as r
|
|
5919
5927
|
};
|
|
5920
|
-
//# sourceMappingURL=engine-
|
|
5928
|
+
//# sourceMappingURL=engine-DMU8HkGx.js.map
|