pdfjs-dist 2.5.207 → 2.6.347
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/bower.json +1 -1
- package/build/pdf.js +867 -216
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +10214 -8547
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.js +2023 -1046
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.min.js +22 -0
- package/es5/build/pdf.worker.js +11136 -8144
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +8 -5
- package/es5/web/pdf_viewer.js +195 -51
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +24 -16
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +479 -43
- package/lib/core/cff_parser.js +643 -615
- package/lib/core/chunked_stream.js +64 -50
- package/lib/core/colorspace.js +126 -104
- package/lib/core/crypto.js +37 -0
- package/lib/core/document.js +128 -75
- package/lib/core/evaluator.js +3015 -2754
- package/lib/core/fonts.js +47 -46
- package/lib/core/function.js +79 -6
- package/lib/core/image.js +364 -357
- package/lib/core/image_utils.js +109 -8
- package/lib/core/jpg.js +8 -3
- package/lib/core/obj.js +255 -34
- package/lib/core/operator_list.js +17 -15
- package/lib/core/parser.js +40 -3
- package/lib/core/pattern.js +24 -11
- package/lib/core/primitives.js +112 -53
- package/lib/core/type1_parser.js +2 -0
- package/lib/core/worker.js +102 -37
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +51 -10
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +140 -54
- package/lib/display/canvas.js +215 -46
- package/lib/display/display_utils.js +55 -18
- package/lib/display/fetch_stream.js +6 -0
- package/lib/display/font_loader.js +26 -15
- package/lib/display/metadata.js +1 -7
- package/lib/display/network.js +0 -14
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/svg.js +1 -1
- package/lib/display/text_layer.js +4 -1
- package/lib/pdf.js +2 -2
- package/lib/pdf.worker.js +2 -2
- package/lib/shared/is_node.js +1 -1
- package/lib/shared/util.js +13 -10
- package/lib/test/unit/annotation_spec.js +520 -50
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +16 -6
- package/lib/test/unit/cmap_spec.js +4 -4
- package/lib/test/unit/colorspace_spec.js +216 -24
- package/lib/test/unit/crypto_spec.js +51 -4
- package/lib/test/unit/custom_spec.js +129 -1
- package/lib/test/unit/document_spec.js +112 -1
- package/lib/test/unit/evaluator_spec.js +29 -10
- package/lib/test/unit/jasmine-boot.js +1 -1
- package/lib/test/unit/metadata_spec.js +3 -3
- package/lib/test/unit/primitives_spec.js +242 -63
- package/lib/test/unit/test_utils.js +42 -89
- package/lib/test/unit/testreporter.js +17 -6
- package/lib/test/unit/util_spec.js +13 -12
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +13 -9
- package/lib/web/app.js +231 -26
- package/lib/web/app_options.js +1 -6
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +53 -4
- package/lib/web/download_manager.js +3 -10
- package/lib/web/firefox_print_service.js +32 -12
- package/lib/web/firefoxcom.js +20 -6
- package/lib/web/interfaces.js +1 -1
- package/lib/web/pdf_attachment_viewer.js +80 -38
- package/lib/web/pdf_find_controller.js +2 -1
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_outline_viewer.js +24 -57
- package/lib/web/pdf_page_view.js +29 -6
- package/lib/web/pdf_print_service.js +13 -11
- package/lib/web/pdf_sidebar.js +46 -25
- package/lib/web/pdf_thumbnail_view.js +16 -3
- package/lib/web/pdf_thumbnail_viewer.js +17 -1
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/preferences.js +1 -1
- package/lib/web/toolbar.js +1 -1
- package/lib/web/ui_utils.js +7 -1
- package/package.json +3 -1
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +8 -5
- package/web/pdf_viewer.js +109 -33
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +1 -9
- package/es5/web/images/texture.png +0 -0
- package/web/images/texture.png +0 -0
package/lib/web/base_viewer.js
CHANGED
@@ -101,6 +101,11 @@ class BaseViewer {
|
|
101
101
|
this._name = this.constructor.name;
|
102
102
|
this.container = options.container;
|
103
103
|
this.viewer = options.viewer || options.container.firstElementChild;
|
104
|
+
|
105
|
+
if (!(this.container instanceof HTMLDivElement && this.viewer instanceof HTMLDivElement)) {
|
106
|
+
throw new Error("Invalid `container` and/or `viewer` option.");
|
107
|
+
}
|
108
|
+
|
104
109
|
this.eventBus = options.eventBus;
|
105
110
|
this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
|
106
111
|
this.downloadManager = options.downloadManager || null;
|
@@ -108,7 +113,7 @@ class BaseViewer {
|
|
108
113
|
this.removePageBorders = options.removePageBorders || false;
|
109
114
|
this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
|
110
115
|
this.imageResourcesPath = options.imageResourcesPath || "";
|
111
|
-
this.renderInteractiveForms = options.renderInteractiveForms
|
116
|
+
this.renderInteractiveForms = typeof options.renderInteractiveForms === "boolean" ? options.renderInteractiveForms : true;
|
112
117
|
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
|
113
118
|
this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
|
114
119
|
this.enableWebGL = options.enableWebGL || false;
|
@@ -339,6 +344,8 @@ class BaseViewer {
|
|
339
344
|
|
340
345
|
const pagesCount = pdfDocument.numPages;
|
341
346
|
const firstPagePromise = pdfDocument.getPage(1);
|
347
|
+
const annotationStorage = pdfDocument.annotationStorage;
|
348
|
+
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
|
342
349
|
|
343
350
|
this._pagesCapability.promise.then(() => {
|
344
351
|
this.eventBus.dispatch("pagesloaded", {
|
@@ -376,6 +383,7 @@ class BaseViewer {
|
|
376
383
|
firstPagePromise.then(firstPdfPage => {
|
377
384
|
this._firstPageCapability.resolve(firstPdfPage);
|
378
385
|
|
386
|
+
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
379
387
|
const scale = this.currentScale;
|
380
388
|
const viewport = firstPdfPage.getViewport({
|
381
389
|
scale: scale * _ui_utils.CSS_UNITS
|
@@ -389,6 +397,8 @@ class BaseViewer {
|
|
389
397
|
id: pageNum,
|
390
398
|
scale,
|
391
399
|
defaultViewport: viewport.clone(),
|
400
|
+
annotationStorage,
|
401
|
+
optionalContentConfigPromise,
|
392
402
|
renderingQueue: this.renderingQueue,
|
393
403
|
textLayerFactory,
|
394
404
|
textLayerMode: this.textLayerMode,
|
@@ -500,6 +510,7 @@ class BaseViewer {
|
|
500
510
|
this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
|
501
511
|
this._location = null;
|
502
512
|
this._pagesRotation = 0;
|
513
|
+
this._optionalContentConfigPromise = null;
|
503
514
|
this._pagesRequests = new WeakMap();
|
504
515
|
this._firstPageCapability = (0, _pdf.createPromiseCapability)();
|
505
516
|
this._onePageRenderedCapability = (0, _pdf.createPromiseCapability)();
|
@@ -971,10 +982,11 @@ class BaseViewer {
|
|
971
982
|
});
|
972
983
|
}
|
973
984
|
|
974
|
-
createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
|
985
|
+
createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
|
975
986
|
return new _annotation_layer_builder.AnnotationLayerBuilder({
|
976
987
|
pageDiv,
|
977
988
|
pdfPage,
|
989
|
+
annotationStorage,
|
978
990
|
imageResourcesPath,
|
979
991
|
renderInteractiveForms,
|
980
992
|
linkService: this.linkService,
|
@@ -1013,9 +1025,8 @@ class BaseViewer {
|
|
1013
1025
|
return pagesOverview;
|
1014
1026
|
}
|
1015
1027
|
|
1016
|
-
const isFirstPagePortrait = (0, _ui_utils.isPortraitOrientation)(pagesOverview[0]);
|
1017
1028
|
return pagesOverview.map(function (size) {
|
1018
|
-
if (
|
1029
|
+
if ((0, _ui_utils.isPortraitOrientation)(size)) {
|
1019
1030
|
return size;
|
1020
1031
|
}
|
1021
1032
|
|
@@ -1027,6 +1038,44 @@ class BaseViewer {
|
|
1027
1038
|
});
|
1028
1039
|
}
|
1029
1040
|
|
1041
|
+
get optionalContentConfigPromise() {
|
1042
|
+
if (!this.pdfDocument) {
|
1043
|
+
return Promise.resolve(null);
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
if (!this._optionalContentConfigPromise) {
|
1047
|
+
return this.pdfDocument.getOptionalContentConfig();
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
return this._optionalContentConfigPromise;
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
set optionalContentConfigPromise(promise) {
|
1054
|
+
if (!(promise instanceof Promise)) {
|
1055
|
+
throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
if (!this.pdfDocument) {
|
1059
|
+
return;
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
if (!this._optionalContentConfigPromise) {
|
1063
|
+
return;
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
this._optionalContentConfigPromise = promise;
|
1067
|
+
|
1068
|
+
for (const pageView of this._pages) {
|
1069
|
+
pageView.update(pageView.scale, pageView.rotation, promise);
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
this.update();
|
1073
|
+
this.eventBus.dispatch("optionalcontentconfigchanged", {
|
1074
|
+
source: this,
|
1075
|
+
promise
|
1076
|
+
});
|
1077
|
+
}
|
1078
|
+
|
1030
1079
|
get scrollMode() {
|
1031
1080
|
return this._scrollMode;
|
1032
1081
|
}
|
@@ -31,7 +31,6 @@ var _pdf = require("../pdf");
|
|
31
31
|
var _viewer_compatibility = require("./viewer_compatibility.js");
|
32
32
|
|
33
33
|
;
|
34
|
-
const DISABLE_CREATE_OBJECT_URL = _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL || false;
|
35
34
|
|
36
35
|
function download(blobUrl, filename) {
|
37
36
|
const a = document.createElement("a");
|
@@ -53,12 +52,6 @@ function download(blobUrl, filename) {
|
|
53
52
|
}
|
54
53
|
|
55
54
|
class DownloadManager {
|
56
|
-
constructor({
|
57
|
-
disableCreateObjectURL = DISABLE_CREATE_OBJECT_URL
|
58
|
-
}) {
|
59
|
-
this.disableCreateObjectURL = disableCreateObjectURL;
|
60
|
-
}
|
61
|
-
|
62
55
|
downloadUrl(url, filename) {
|
63
56
|
if (!(0, _pdf.createValidAbsoluteUrl)(url, "http://example.com")) {
|
64
57
|
return;
|
@@ -75,11 +68,11 @@ class DownloadManager {
|
|
75
68
|
return;
|
76
69
|
}
|
77
70
|
|
78
|
-
const blobUrl = (0, _pdf.createObjectURL)(data, contentType,
|
71
|
+
const blobUrl = (0, _pdf.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
|
79
72
|
download(blobUrl, filename);
|
80
73
|
}
|
81
74
|
|
82
|
-
download(blob, url, filename) {
|
75
|
+
download(blob, url, filename, sourceEventType = "download") {
|
83
76
|
if (navigator.msSaveBlob) {
|
84
77
|
if (!navigator.msSaveBlob(blob, filename)) {
|
85
78
|
this.downloadUrl(url, filename);
|
@@ -88,7 +81,7 @@ class DownloadManager {
|
|
88
81
|
return;
|
89
82
|
}
|
90
83
|
|
91
|
-
if (
|
84
|
+
if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
|
92
85
|
this.downloadUrl(url, filename);
|
93
86
|
return;
|
94
87
|
}
|
@@ -26,18 +26,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.FirefoxPrintService = FirefoxPrintService;
|
28
28
|
|
29
|
-
var _app_options = require("./app_options.js");
|
30
|
-
|
31
29
|
var _ui_utils = require("./ui_utils.js");
|
32
30
|
|
33
31
|
var _app = require("./app.js");
|
34
32
|
|
35
33
|
var _pdf = require("../pdf");
|
36
34
|
|
37
|
-
function composePage(pdfDocument, pageNumber, size, printContainer) {
|
35
|
+
function composePage(pdfDocument, pageNumber, size, printContainer, printResolution, optionalContentConfigPromise) {
|
38
36
|
const canvas = document.createElement("canvas");
|
39
|
-
const
|
40
|
-
const PRINT_UNITS = PRINT_RESOLUTION / 72.0;
|
37
|
+
const PRINT_UNITS = printResolution / 72.0;
|
41
38
|
canvas.width = Math.floor(size.width * PRINT_UNITS);
|
42
39
|
canvas.height = Math.floor(size.height * PRINT_UNITS);
|
43
40
|
canvas.style.width = Math.floor(size.width * _ui_utils.CSS_UNITS) + "px";
|
@@ -45,6 +42,7 @@ function composePage(pdfDocument, pageNumber, size, printContainer) {
|
|
45
42
|
const canvasWrapper = document.createElement("div");
|
46
43
|
canvasWrapper.appendChild(canvas);
|
47
44
|
printContainer.appendChild(canvasWrapper);
|
45
|
+
let currentRenderTask = null;
|
48
46
|
|
49
47
|
canvas.mozPrintCallback = function (obj) {
|
50
48
|
const ctx = obj.context;
|
@@ -52,7 +50,13 @@ function composePage(pdfDocument, pageNumber, size, printContainer) {
|
|
52
50
|
ctx.fillStyle = "rgb(255, 255, 255)";
|
53
51
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
54
52
|
ctx.restore();
|
53
|
+
let thisRenderTask = null;
|
55
54
|
pdfDocument.getPage(pageNumber).then(function (pdfPage) {
|
55
|
+
if (currentRenderTask) {
|
56
|
+
currentRenderTask.cancel();
|
57
|
+
currentRenderTask = null;
|
58
|
+
}
|
59
|
+
|
56
60
|
const renderContext = {
|
57
61
|
canvasContext: ctx,
|
58
62
|
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
@@ -60,14 +64,26 @@ function composePage(pdfDocument, pageNumber, size, printContainer) {
|
|
60
64
|
scale: 1,
|
61
65
|
rotation: size.rotation
|
62
66
|
}),
|
63
|
-
intent: "print"
|
67
|
+
intent: "print",
|
68
|
+
annotationStorage: pdfDocument.annotationStorage,
|
69
|
+
optionalContentConfigPromise
|
64
70
|
};
|
65
|
-
|
71
|
+
currentRenderTask = thisRenderTask = pdfPage.render(renderContext);
|
72
|
+
return thisRenderTask.promise;
|
66
73
|
}).then(function () {
|
74
|
+
if (currentRenderTask === thisRenderTask) {
|
75
|
+
currentRenderTask = null;
|
76
|
+
}
|
77
|
+
|
67
78
|
obj.done();
|
68
79
|
}, function (error) {
|
69
80
|
console.error(error);
|
70
81
|
|
82
|
+
if (currentRenderTask === thisRenderTask) {
|
83
|
+
currentRenderTask.cancel();
|
84
|
+
currentRenderTask = null;
|
85
|
+
}
|
86
|
+
|
71
87
|
if ("abort" in obj) {
|
72
88
|
obj.abort();
|
73
89
|
} else {
|
@@ -77,10 +93,12 @@ function composePage(pdfDocument, pageNumber, size, printContainer) {
|
|
77
93
|
};
|
78
94
|
}
|
79
95
|
|
80
|
-
function FirefoxPrintService(pdfDocument, pagesOverview, printContainer) {
|
96
|
+
function FirefoxPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null) {
|
81
97
|
this.pdfDocument = pdfDocument;
|
82
98
|
this.pagesOverview = pagesOverview;
|
83
99
|
this.printContainer = printContainer;
|
100
|
+
this._printResolution = printResolution || 150;
|
101
|
+
this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
|
84
102
|
}
|
85
103
|
|
86
104
|
FirefoxPrintService.prototype = {
|
@@ -88,13 +106,15 @@ FirefoxPrintService.prototype = {
|
|
88
106
|
const {
|
89
107
|
pdfDocument,
|
90
108
|
pagesOverview,
|
91
|
-
printContainer
|
109
|
+
printContainer,
|
110
|
+
_printResolution,
|
111
|
+
_optionalContentConfigPromise
|
92
112
|
} = this;
|
93
113
|
const body = document.querySelector("body");
|
94
114
|
body.setAttribute("data-pdfjsprinting", true);
|
95
115
|
|
96
116
|
for (let i = 0, ii = pagesOverview.length; i < ii; ++i) {
|
97
|
-
composePage(pdfDocument, i + 1, pagesOverview[i], printContainer);
|
117
|
+
composePage(pdfDocument, i + 1, pagesOverview[i], printContainer, _printResolution, _optionalContentConfigPromise);
|
98
118
|
}
|
99
119
|
},
|
100
120
|
|
@@ -112,8 +132,8 @@ _app.PDFPrintServiceFactory.instance = {
|
|
112
132
|
return (0, _pdf.shadow)(this, "supportsPrinting", value);
|
113
133
|
},
|
114
134
|
|
115
|
-
createPrintService(pdfDocument, pagesOverview, printContainer) {
|
116
|
-
return new FirefoxPrintService(pdfDocument, pagesOverview, printContainer);
|
135
|
+
createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise) {
|
136
|
+
return new FirefoxPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise);
|
117
137
|
}
|
118
138
|
|
119
139
|
};
|
package/lib/web/firefoxcom.js
CHANGED
@@ -87,10 +87,6 @@ const FirefoxCom = function FirefoxComClosure() {
|
|
87
87
|
exports.FirefoxCom = FirefoxCom;
|
88
88
|
|
89
89
|
class DownloadManager {
|
90
|
-
constructor(options) {
|
91
|
-
this.disableCreateObjectURL = false;
|
92
|
-
}
|
93
|
-
|
94
90
|
downloadUrl(url, filename) {
|
95
91
|
FirefoxCom.request("download", {
|
96
92
|
originalUrl: url,
|
@@ -115,7 +111,7 @@ class DownloadManager {
|
|
115
111
|
}, onResponse);
|
116
112
|
}
|
117
113
|
|
118
|
-
download(blob, url, filename) {
|
114
|
+
download(blob, url, filename, sourceEventType = "download") {
|
119
115
|
const blobUrl = URL.createObjectURL(blob);
|
120
116
|
|
121
117
|
const onResponse = err => {
|
@@ -129,7 +125,8 @@ class DownloadManager {
|
|
129
125
|
FirefoxCom.request("download", {
|
130
126
|
blobUrl,
|
131
127
|
originalUrl: url,
|
132
|
-
filename
|
128
|
+
filename,
|
129
|
+
sourceEventType
|
133
130
|
}, onResponse);
|
134
131
|
}
|
135
132
|
|
@@ -239,6 +236,23 @@ class MozL10n {
|
|
239
236
|
}
|
240
237
|
})();
|
241
238
|
|
239
|
+
(function listenSaveEvent() {
|
240
|
+
const handleEvent = function ({
|
241
|
+
type,
|
242
|
+
detail
|
243
|
+
}) {
|
244
|
+
if (!_app.PDFViewerApplication.initialized) {
|
245
|
+
return;
|
246
|
+
}
|
247
|
+
|
248
|
+
_app.PDFViewerApplication.eventBus.dispatch(type, {
|
249
|
+
source: window
|
250
|
+
});
|
251
|
+
};
|
252
|
+
|
253
|
+
window.addEventListener("save", handleEvent);
|
254
|
+
})();
|
255
|
+
|
242
256
|
class FirefoxComDataRangeTransport extends _pdf.PDFDataRangeTransport {
|
243
257
|
requestDataRange(begin, end) {
|
244
258
|
FirefoxCom.request("requestDataRange", {
|
package/lib/web/interfaces.js
CHANGED
@@ -105,7 +105,7 @@ class IPDFTextLayerFactory {
|
|
105
105
|
exports.IPDFTextLayerFactory = IPDFTextLayerFactory;
|
106
106
|
|
107
107
|
class IPDFAnnotationLayerFactory {
|
108
|
-
createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms =
|
108
|
+
createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = undefined) {}
|
109
109
|
|
110
110
|
}
|
111
111
|
|
@@ -28,42 +28,67 @@ exports.PDFAttachmentViewer = void 0;
|
|
28
28
|
|
29
29
|
var _pdf = require("../pdf");
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
this.
|
31
|
+
var _base_tree_viewer = require("./base_tree_viewer.js");
|
32
|
+
|
33
|
+
var _viewer_compatibility = require("./viewer_compatibility.js");
|
34
|
+
|
35
|
+
const PdfFileRegExp = /\.pdf$/i;
|
36
|
+
|
37
|
+
class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
|
38
|
+
constructor(options) {
|
39
|
+
super(options);
|
40
|
+
this.downloadManager = options.downloadManager;
|
41
41
|
|
42
42
|
this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
|
43
43
|
}
|
44
44
|
|
45
45
|
reset(keepRenderedCapability = false) {
|
46
|
-
|
47
|
-
this.
|
46
|
+
super.reset();
|
47
|
+
this._attachments = null;
|
48
48
|
|
49
49
|
if (!keepRenderedCapability) {
|
50
50
|
this._renderedCapability = (0, _pdf.createPromiseCapability)();
|
51
51
|
}
|
52
|
+
|
53
|
+
if (this._pendingDispatchEvent) {
|
54
|
+
clearTimeout(this._pendingDispatchEvent);
|
55
|
+
}
|
56
|
+
|
57
|
+
this._pendingDispatchEvent = null;
|
52
58
|
}
|
53
59
|
|
54
60
|
_dispatchEvent(attachmentsCount) {
|
55
61
|
this._renderedCapability.resolve();
|
56
62
|
|
63
|
+
if (this._pendingDispatchEvent) {
|
64
|
+
clearTimeout(this._pendingDispatchEvent);
|
65
|
+
this._pendingDispatchEvent = null;
|
66
|
+
}
|
67
|
+
|
68
|
+
if (attachmentsCount === 0) {
|
69
|
+
this._pendingDispatchEvent = setTimeout(() => {
|
70
|
+
this.eventBus.dispatch("attachmentsloaded", {
|
71
|
+
source: this,
|
72
|
+
attachmentsCount: 0
|
73
|
+
});
|
74
|
+
this._pendingDispatchEvent = null;
|
75
|
+
});
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
|
57
79
|
this.eventBus.dispatch("attachmentsloaded", {
|
58
80
|
source: this,
|
59
81
|
attachmentsCount
|
60
82
|
});
|
61
83
|
}
|
62
84
|
|
63
|
-
_bindPdfLink(
|
85
|
+
_bindPdfLink(element, {
|
86
|
+
content,
|
87
|
+
filename
|
88
|
+
}) {
|
64
89
|
let blobUrl;
|
65
90
|
|
66
|
-
|
91
|
+
element.onclick = () => {
|
67
92
|
if (!blobUrl) {
|
68
93
|
blobUrl = URL.createObjectURL(new Blob([content], {
|
69
94
|
type: "application/pdf"
|
@@ -86,9 +111,13 @@ class PDFAttachmentViewer {
|
|
86
111
|
};
|
87
112
|
}
|
88
113
|
|
89
|
-
_bindLink(
|
90
|
-
|
91
|
-
|
114
|
+
_bindLink(element, {
|
115
|
+
content,
|
116
|
+
filename
|
117
|
+
}) {
|
118
|
+
element.onclick = () => {
|
119
|
+
const contentType = PdfFileRegExp.test(filename) ? "application/pdf" : "";
|
120
|
+
this.downloadManager.downloadData(content, filename, contentType);
|
92
121
|
return false;
|
93
122
|
};
|
94
123
|
}
|
@@ -97,16 +126,14 @@ class PDFAttachmentViewer {
|
|
97
126
|
attachments,
|
98
127
|
keepRenderedCapability = false
|
99
128
|
}) {
|
100
|
-
|
101
|
-
|
102
|
-
if (this.attachments) {
|
103
|
-
this.reset(keepRenderedCapability === true);
|
129
|
+
if (this._attachments) {
|
130
|
+
this.reset(keepRenderedCapability);
|
104
131
|
}
|
105
132
|
|
106
|
-
this.
|
133
|
+
this._attachments = attachments || null;
|
107
134
|
|
108
135
|
if (!attachments) {
|
109
|
-
this._dispatchEvent(
|
136
|
+
this._dispatchEvent(0);
|
110
137
|
|
111
138
|
return;
|
112
139
|
}
|
@@ -114,26 +141,36 @@ class PDFAttachmentViewer {
|
|
114
141
|
const names = Object.keys(attachments).sort(function (a, b) {
|
115
142
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
116
143
|
});
|
117
|
-
|
144
|
+
const fragment = document.createDocumentFragment();
|
145
|
+
let attachmentsCount = 0;
|
118
146
|
|
119
|
-
for (
|
120
|
-
const item = attachments[
|
121
|
-
const filename = (0, _pdf.
|
147
|
+
for (const name of names) {
|
148
|
+
const item = attachments[name];
|
149
|
+
const filename = (0, _pdf.getFilenameFromUrl)(item.filename);
|
122
150
|
const div = document.createElement("div");
|
123
|
-
div.className = "
|
124
|
-
const
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
151
|
+
div.className = "treeItem";
|
152
|
+
const element = document.createElement("a");
|
153
|
+
|
154
|
+
if (PdfFileRegExp.test(filename) && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
|
155
|
+
this._bindPdfLink(element, {
|
156
|
+
content: item.content,
|
157
|
+
filename
|
158
|
+
});
|
129
159
|
} else {
|
130
|
-
this._bindLink(
|
160
|
+
this._bindLink(element, {
|
161
|
+
content: item.content,
|
162
|
+
filename
|
163
|
+
});
|
131
164
|
}
|
132
165
|
|
133
|
-
|
134
|
-
|
166
|
+
element.textContent = this._normalizeTextContent(filename);
|
167
|
+
div.appendChild(element);
|
168
|
+
fragment.appendChild(div);
|
169
|
+
attachmentsCount++;
|
135
170
|
}
|
136
171
|
|
172
|
+
this.container.appendChild(fragment);
|
173
|
+
|
137
174
|
this._dispatchEvent(attachmentsCount);
|
138
175
|
}
|
139
176
|
|
@@ -142,8 +179,13 @@ class PDFAttachmentViewer {
|
|
142
179
|
filename,
|
143
180
|
content
|
144
181
|
}) {
|
145
|
-
this._renderedCapability.promise
|
146
|
-
|
182
|
+
const renderedPromise = this._renderedCapability.promise;
|
183
|
+
renderedPromise.then(() => {
|
184
|
+
if (renderedPromise !== this._renderedCapability.promise) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
|
188
|
+
let attachments = this._attachments;
|
147
189
|
|
148
190
|
if (!attachments) {
|
149
191
|
attachments = Object.create(null);
|