@vertexvis/doc-viewer 1.0.2-canary.0 → 1.0.2-canary.10
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/cjs/vertex-document-viewer.cjs.entry.js +64 -29
- package/dist/collection/__mocks__/pdfjs-mock.js +2 -1
- package/dist/collection/components/document-viewer/document-viewer.css +11 -0
- package/dist/collection/components/document-viewer/document-viewer.js +18 -6
- package/dist/collection/lib/document/layers/controller.js +12 -0
- package/dist/collection/lib/dom.js +3 -0
- package/dist/collection/lib/interactions/pan-interaction-handler.js +1 -1
- package/dist/collection/lib/pdf/pdfjs-renderer.js +10 -1
- package/dist/components/vertex-document-viewer.js +2 -2
- package/dist/doc-viewer/doc-viewer.esm.js +1 -1
- package/dist/doc-viewer/{p-00ba8fe3.entry.js → p-465c1030.entry.js} +2 -2
- package/dist/esm/vertex-document-viewer.entry.js +64 -29
- package/dist/types/__mocks__/pdfjs-mock.d.ts +2 -2
- package/dist/types/components/document-viewer/document-viewer.d.ts +1 -0
- package/dist/types/lib/document/layers/controller.d.ts +3 -1
- package/dist/types/lib/dom.d.ts +1 -0
- package/package.json +4 -4
|
@@ -285,21 +285,21 @@ function fromJson$5(json) {
|
|
|
285
285
|
|
|
286
286
|
var point = /*#__PURE__*/Object.freeze({
|
|
287
287
|
__proto__: null,
|
|
288
|
+
add: add$1,
|
|
288
289
|
create: create$d,
|
|
289
|
-
polar: polar,
|
|
290
290
|
distance: distance$2,
|
|
291
|
-
|
|
292
|
-
add: add$1,
|
|
291
|
+
fromJson: fromJson$5,
|
|
293
292
|
isEqual: isEqual$3,
|
|
294
293
|
lerp: lerp$1,
|
|
295
|
-
negate: negate$1,
|
|
296
|
-
scale: scale$5,
|
|
297
|
-
scaleProportional: scaleProportional,
|
|
298
294
|
magnitude: magnitude$2,
|
|
299
|
-
|
|
295
|
+
negate: negate$1,
|
|
300
296
|
normalDirectionVector: normalDirectionVector,
|
|
297
|
+
normalizeVector: normalizeVector,
|
|
301
298
|
orthogonalVector: orthogonalVector,
|
|
302
|
-
|
|
299
|
+
polar: polar,
|
|
300
|
+
scale: scale$5,
|
|
301
|
+
scaleProportional: scaleProportional,
|
|
302
|
+
subtract: subtract$1
|
|
303
303
|
});
|
|
304
304
|
|
|
305
305
|
/**
|
|
@@ -510,22 +510,22 @@ function toRectangle(dimensions, position) {
|
|
|
510
510
|
|
|
511
511
|
var dimensions = /*#__PURE__*/Object.freeze({
|
|
512
512
|
__proto__: null,
|
|
513
|
+
area: area,
|
|
514
|
+
aspectRatio: aspectRatio,
|
|
515
|
+
center: center$1,
|
|
516
|
+
containFit: containFit,
|
|
513
517
|
create: create$6,
|
|
514
|
-
|
|
518
|
+
cropFit: cropFit,
|
|
519
|
+
fitToRatio: fitToRatio,
|
|
520
|
+
floor: floor$1,
|
|
515
521
|
isEqual: isEqual,
|
|
516
|
-
scale: scale,
|
|
517
522
|
proportionalScale: proportionalScale,
|
|
518
|
-
trim: trim,
|
|
519
|
-
containFit: containFit,
|
|
520
|
-
cropFit: cropFit,
|
|
521
|
-
scaleFit: scaleFit,
|
|
522
523
|
round: round,
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
toRectangle: toRectangle
|
|
524
|
+
scale: scale,
|
|
525
|
+
scaleFit: scaleFit,
|
|
526
|
+
square: square,
|
|
527
|
+
toRectangle: toRectangle,
|
|
528
|
+
trim: trim
|
|
529
529
|
});
|
|
530
530
|
|
|
531
531
|
var classnames = {exports: {}};
|
|
@@ -625,10 +625,22 @@ function apiSupportsLayers(api) {
|
|
|
625
625
|
class DocumentLayersController {
|
|
626
626
|
constructor(api) {
|
|
627
627
|
this.apiSupportsLayers = false;
|
|
628
|
+
if (api != null) {
|
|
629
|
+
this.setApi(api);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
setApi(api) {
|
|
628
633
|
if (apiSupportsLayers(api)) {
|
|
629
634
|
this.apiSupportsLayers = true;
|
|
630
635
|
this.api = api;
|
|
631
636
|
}
|
|
637
|
+
else {
|
|
638
|
+
this.clear();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
clear() {
|
|
642
|
+
this.apiSupportsLayers = false;
|
|
643
|
+
this.api = undefined;
|
|
632
644
|
}
|
|
633
645
|
/**
|
|
634
646
|
* Returns a boolean indicating whether the document supports layers.
|
|
@@ -663,6 +675,9 @@ class DocumentLayersController {
|
|
|
663
675
|
function getElementBoundingClientRect(element) {
|
|
664
676
|
return element.getBoundingClientRect();
|
|
665
677
|
}
|
|
678
|
+
function createElement(tagName) {
|
|
679
|
+
return document.createElement(tagName);
|
|
680
|
+
}
|
|
666
681
|
function getAllVertexElementChildren(element) {
|
|
667
682
|
return getAllChildren(element)
|
|
668
683
|
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
@@ -702,7 +717,7 @@ class PanInteractionHandler {
|
|
|
702
717
|
}
|
|
703
718
|
}
|
|
704
719
|
handlePointerDown(event) {
|
|
705
|
-
if (event.button !==
|
|
720
|
+
if (event.button !== 2) {
|
|
706
721
|
return;
|
|
707
722
|
}
|
|
708
723
|
event.preventDefault();
|
|
@@ -34545,7 +34560,7 @@ class PdfJsRenderer extends DocumentRenderer {
|
|
|
34545
34560
|
this.state = { pages: {}, rendering: false };
|
|
34546
34561
|
// Render pages using an offscreen canvas to avoid flickering that can occur for
|
|
34547
34562
|
// PDFs with annotations.
|
|
34548
|
-
this.offscreenCanvas =
|
|
34563
|
+
this.offscreenCanvas = createElement('canvas');
|
|
34549
34564
|
this.handleStateChanged = this.handleStateChanged.bind(this);
|
|
34550
34565
|
this.stateChangedDisposable = this.api.onStateChanged(this.handleStateChanged);
|
|
34551
34566
|
}
|
|
@@ -34587,10 +34602,18 @@ class PdfJsRenderer extends DocumentRenderer {
|
|
|
34587
34602
|
});
|
|
34588
34603
|
this.offscreenCanvas.width = this.canvas.width;
|
|
34589
34604
|
this.offscreenCanvas.height = this.canvas.height;
|
|
34605
|
+
const offscreenCanvasCtx = this.offscreenCanvas.getContext('2d');
|
|
34606
|
+
// Fill the offscreen canvas with a white background prior to rendering the page to give the content
|
|
34607
|
+
// of the PDF a white background, but maintain the canvas it gets drawn to when copying to the main canvas.
|
|
34608
|
+
if (offscreenCanvasCtx != null) {
|
|
34609
|
+
offscreenCanvasCtx.fillStyle = '#ffffff';
|
|
34610
|
+
offscreenCanvasCtx.fillRect(panOffset.x + centerOffsetX, panOffset.y, scaled.width, scaled.height);
|
|
34611
|
+
}
|
|
34590
34612
|
await page.render({
|
|
34591
34613
|
canvas: this.offscreenCanvas,
|
|
34592
34614
|
viewport: scaled,
|
|
34593
34615
|
intent: 'display',
|
|
34616
|
+
background: 'transparent',
|
|
34594
34617
|
optionalContentConfigPromise: optionalContentConfig != null ? Promise.resolve(optionalContentConfig) : undefined,
|
|
34595
34618
|
}).promise;
|
|
34596
34619
|
// Emit an event before the page is drawn, then draw the page to the canvas on the next
|
|
@@ -34620,7 +34643,7 @@ class PdfJsProvider {
|
|
|
34620
34643
|
}
|
|
34621
34644
|
}
|
|
34622
34645
|
|
|
34623
|
-
const documentViewerCss = () => `:host{display:block;position:relative;width:300px;height:300px;min-width:1px;min-height:1px;user-select:none;-webkit-user-select:none}.viewer-container{width:100%;height:100%;overflow:hidden}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative}`;
|
|
34646
|
+
const documentViewerCss = () => `:host{display:block;position:relative;width:300px;height:300px;min-width:1px;min-height:1px;user-select:none;-webkit-user-select:none;--viewer-background:#cccccc}.viewer-container{width:100%;height:100%;overflow:hidden}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative}#document-viewer-canvas{background-color:var(--viewer-background)}`;
|
|
34624
34647
|
|
|
34625
34648
|
const VertexDocumentViewer = class {
|
|
34626
34649
|
constructor(hostRef) {
|
|
@@ -34652,6 +34675,7 @@ const VertexDocumentViewer = class {
|
|
|
34652
34675
|
this.handleDocumentApiStateChanged = this.handleDocumentApiStateChanged.bind(this);
|
|
34653
34676
|
this.handlePageLoaded = this.handlePageLoaded.bind(this);
|
|
34654
34677
|
this.handlePageDrawn = this.handlePageDrawn.bind(this);
|
|
34678
|
+
this.layers = new DocumentLayersController();
|
|
34655
34679
|
this.resizeObserver = new ResizeObserver(this.handleElementResize);
|
|
34656
34680
|
this.registerSlotChangeListeners();
|
|
34657
34681
|
}
|
|
@@ -34664,7 +34688,7 @@ const VertexDocumentViewer = class {
|
|
|
34664
34688
|
var _a;
|
|
34665
34689
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
|
|
34666
34690
|
this.updateComponentDimensions();
|
|
34667
|
-
this.
|
|
34691
|
+
this.loadInitialSrc();
|
|
34668
34692
|
this.injectViewerApi();
|
|
34669
34693
|
}
|
|
34670
34694
|
disconnectedCallback() {
|
|
@@ -34731,12 +34755,13 @@ const VertexDocumentViewer = class {
|
|
|
34731
34755
|
await documentApi.loadPage(pageNumber);
|
|
34732
34756
|
}
|
|
34733
34757
|
async handleSrcChange() {
|
|
34758
|
+
var _a;
|
|
34734
34759
|
if (this.src != null && this.canvasEl != null) {
|
|
34735
34760
|
this.clearCurrentDocument();
|
|
34736
34761
|
const { api, renderer } = this.provider.create(this.canvasEl, this.config);
|
|
34737
34762
|
this.documentApi = api;
|
|
34738
34763
|
this.documentRenderer = renderer;
|
|
34739
|
-
this.layers
|
|
34764
|
+
(_a = this.layers) === null || _a === void 0 ? void 0 : _a.setApi(api);
|
|
34740
34765
|
this.updateInteractionHandler();
|
|
34741
34766
|
this.updateDocumentApiListeners();
|
|
34742
34767
|
await this.documentApi.updateViewport(this.dimensions);
|
|
@@ -34753,9 +34778,9 @@ const VertexDocumentViewer = class {
|
|
|
34753
34778
|
this.updateInteractionHandler();
|
|
34754
34779
|
}
|
|
34755
34780
|
render() {
|
|
34756
|
-
return (index.h(index.Host, { key: '
|
|
34781
|
+
return (index.h(index.Host, { key: 'a990831d5f2328f2cf21be0b82d4018b05decd51' }, index.h("div", { key: '349abae36254da570e640417fab459680c576465', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, index.h("div", { key: '6fca3f1d5a2c31bdcc0c8dbbd468e306db981740', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
|
|
34757
34782
|
'enable-pointer-events ': window.PointerEvent != null,
|
|
34758
|
-
}) }, index.h("canvas", { key: '
|
|
34783
|
+
}) }, index.h("canvas", { key: 'deb1c58d8d20000053cd829401163bf1e68ca88e', id: "document-viewer-canvas", role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: '6b87846ef17b330b0fae5d03103765bad6fdafa6' }))));
|
|
34759
34784
|
}
|
|
34760
34785
|
getDocumentApi() {
|
|
34761
34786
|
if (this.documentApi == null) {
|
|
@@ -34763,15 +34788,25 @@ const VertexDocumentViewer = class {
|
|
|
34763
34788
|
}
|
|
34764
34789
|
return this.documentApi;
|
|
34765
34790
|
}
|
|
34791
|
+
async loadInitialSrc() {
|
|
34792
|
+
await Promise.resolve();
|
|
34793
|
+
await this.handleSrcChange();
|
|
34794
|
+
}
|
|
34766
34795
|
clearCurrentDocument() {
|
|
34767
|
-
var _a, _b, _c, _d, _e, _f;
|
|
34796
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
34768
34797
|
(_a = this.documentRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
34769
34798
|
(_b = this.documentApi) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
34770
34799
|
(_c = this.panInteractionHandler) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
34771
34800
|
(_d = this.documentApiStateChangedDisposable) === null || _d === void 0 ? void 0 : _d.dispose();
|
|
34772
34801
|
(_e = this.pageLoadedDisposable) === null || _e === void 0 ? void 0 : _e.dispose();
|
|
34773
34802
|
(_f = this.pageDrawnDisposable) === null || _f === void 0 ? void 0 : _f.dispose();
|
|
34774
|
-
this.
|
|
34803
|
+
this.documentRenderer = undefined;
|
|
34804
|
+
this.documentApi = undefined;
|
|
34805
|
+
this.panInteractionHandler = undefined;
|
|
34806
|
+
this.documentApiStateChangedDisposable = undefined;
|
|
34807
|
+
this.pageLoadedDisposable = undefined;
|
|
34808
|
+
this.pageDrawnDisposable = undefined;
|
|
34809
|
+
(_g = this.layers) === null || _g === void 0 ? void 0 : _g.clear();
|
|
34775
34810
|
}
|
|
34776
34811
|
handleDocumentApiStateChanged(state) {
|
|
34777
34812
|
this.documentState = state;
|
|
@@ -8,7 +8,8 @@ export class MockOptionalContentConfig extends Map {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export const mockGetViewport = jest.fn(() => ({ width: 100, height: 100 }));
|
|
11
|
-
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
export const mockPageRender = jest.fn((args) => ({ promise: Promise.resolve() }));
|
|
12
13
|
export const mockGetPage = jest.fn(() => ({
|
|
13
14
|
getTextContent: jest.fn(() => ({
|
|
14
15
|
items: [],
|
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
user-select: none;
|
|
10
10
|
-webkit-user-select: none;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @prop --viewer-background:
|
|
14
|
+
* A CSS color value used as the background painted behind the loaded PDF,
|
|
15
|
+
* visible in the negative space around the page. Defaults to #cccccc.
|
|
16
|
+
*/
|
|
17
|
+
--viewer-background: #cccccc;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
.viewer-container {
|
|
@@ -24,3 +31,7 @@
|
|
|
24
31
|
height: 100%;
|
|
25
32
|
position: relative;
|
|
26
33
|
}
|
|
34
|
+
|
|
35
|
+
#document-viewer-canvas {
|
|
36
|
+
background-color: var(--viewer-background);
|
|
37
|
+
}
|
|
@@ -34,6 +34,7 @@ export class VertexDocumentViewer {
|
|
|
34
34
|
this.handleDocumentApiStateChanged = this.handleDocumentApiStateChanged.bind(this);
|
|
35
35
|
this.handlePageLoaded = this.handlePageLoaded.bind(this);
|
|
36
36
|
this.handlePageDrawn = this.handlePageDrawn.bind(this);
|
|
37
|
+
this.layers = new DocumentLayersController();
|
|
37
38
|
this.resizeObserver = new ResizeObserver(this.handleElementResize);
|
|
38
39
|
this.registerSlotChangeListeners();
|
|
39
40
|
}
|
|
@@ -46,7 +47,7 @@ export class VertexDocumentViewer {
|
|
|
46
47
|
var _a;
|
|
47
48
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
|
|
48
49
|
this.updateComponentDimensions();
|
|
49
|
-
this.
|
|
50
|
+
this.loadInitialSrc();
|
|
50
51
|
this.injectViewerApi();
|
|
51
52
|
}
|
|
52
53
|
disconnectedCallback() {
|
|
@@ -113,12 +114,13 @@ export class VertexDocumentViewer {
|
|
|
113
114
|
await documentApi.loadPage(pageNumber);
|
|
114
115
|
}
|
|
115
116
|
async handleSrcChange() {
|
|
117
|
+
var _a;
|
|
116
118
|
if (this.src != null && this.canvasEl != null) {
|
|
117
119
|
this.clearCurrentDocument();
|
|
118
120
|
const { api, renderer } = this.provider.create(this.canvasEl, this.config);
|
|
119
121
|
this.documentApi = api;
|
|
120
122
|
this.documentRenderer = renderer;
|
|
121
|
-
this.layers
|
|
123
|
+
(_a = this.layers) === null || _a === void 0 ? void 0 : _a.setApi(api);
|
|
122
124
|
this.updateInteractionHandler();
|
|
123
125
|
this.updateDocumentApiListeners();
|
|
124
126
|
await this.documentApi.updateViewport(this.dimensions);
|
|
@@ -135,9 +137,9 @@ export class VertexDocumentViewer {
|
|
|
135
137
|
this.updateInteractionHandler();
|
|
136
138
|
}
|
|
137
139
|
render() {
|
|
138
|
-
return (h(Host, { key: '
|
|
140
|
+
return (h(Host, { key: 'a990831d5f2328f2cf21be0b82d4018b05decd51' }, h("div", { key: '349abae36254da570e640417fab459680c576465', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, h("div", { key: '6fca3f1d5a2c31bdcc0c8dbbd468e306db981740', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
|
|
139
141
|
'enable-pointer-events ': window.PointerEvent != null,
|
|
140
|
-
}) }, h("canvas", { key: '
|
|
142
|
+
}) }, h("canvas", { key: 'deb1c58d8d20000053cd829401163bf1e68ca88e', id: "document-viewer-canvas", role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: '6b87846ef17b330b0fae5d03103765bad6fdafa6' }))));
|
|
141
143
|
}
|
|
142
144
|
getDocumentApi() {
|
|
143
145
|
if (this.documentApi == null) {
|
|
@@ -145,15 +147,25 @@ export class VertexDocumentViewer {
|
|
|
145
147
|
}
|
|
146
148
|
return this.documentApi;
|
|
147
149
|
}
|
|
150
|
+
async loadInitialSrc() {
|
|
151
|
+
await Promise.resolve();
|
|
152
|
+
await this.handleSrcChange();
|
|
153
|
+
}
|
|
148
154
|
clearCurrentDocument() {
|
|
149
|
-
var _a, _b, _c, _d, _e, _f;
|
|
155
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
150
156
|
(_a = this.documentRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
151
157
|
(_b = this.documentApi) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
152
158
|
(_c = this.panInteractionHandler) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
153
159
|
(_d = this.documentApiStateChangedDisposable) === null || _d === void 0 ? void 0 : _d.dispose();
|
|
154
160
|
(_e = this.pageLoadedDisposable) === null || _e === void 0 ? void 0 : _e.dispose();
|
|
155
161
|
(_f = this.pageDrawnDisposable) === null || _f === void 0 ? void 0 : _f.dispose();
|
|
156
|
-
this.
|
|
162
|
+
this.documentRenderer = undefined;
|
|
163
|
+
this.documentApi = undefined;
|
|
164
|
+
this.panInteractionHandler = undefined;
|
|
165
|
+
this.documentApiStateChangedDisposable = undefined;
|
|
166
|
+
this.pageLoadedDisposable = undefined;
|
|
167
|
+
this.pageDrawnDisposable = undefined;
|
|
168
|
+
(_g = this.layers) === null || _g === void 0 ? void 0 : _g.clear();
|
|
157
169
|
}
|
|
158
170
|
handleDocumentApiStateChanged(state) {
|
|
159
171
|
this.documentState = state;
|
|
@@ -5,10 +5,22 @@ import { apiSupportsLayers } from "./types";
|
|
|
5
5
|
export class DocumentLayersController {
|
|
6
6
|
constructor(api) {
|
|
7
7
|
this.apiSupportsLayers = false;
|
|
8
|
+
if (api != null) {
|
|
9
|
+
this.setApi(api);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
setApi(api) {
|
|
8
13
|
if (apiSupportsLayers(api)) {
|
|
9
14
|
this.apiSupportsLayers = true;
|
|
10
15
|
this.api = api;
|
|
11
16
|
}
|
|
17
|
+
else {
|
|
18
|
+
this.clear();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this.apiSupportsLayers = false;
|
|
23
|
+
this.api = undefined;
|
|
12
24
|
}
|
|
13
25
|
/**
|
|
14
26
|
* Returns a boolean indicating whether the document supports layers.
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
export function getElementBoundingClientRect(element) {
|
|
5
5
|
return element.getBoundingClientRect();
|
|
6
6
|
}
|
|
7
|
+
export function createElement(tagName) {
|
|
8
|
+
return document.createElement(tagName);
|
|
9
|
+
}
|
|
7
10
|
export function getAllVertexElementChildren(element) {
|
|
8
11
|
return getAllChildren(element)
|
|
9
12
|
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Dimensions } from "@vertexvis/geometry";
|
|
5
5
|
import { DocumentRenderer } from "../document/renderer";
|
|
6
|
+
import { createElement } from "../dom";
|
|
6
7
|
export class PdfJsRenderer extends DocumentRenderer {
|
|
7
8
|
constructor(api, canvas) {
|
|
8
9
|
super(api, canvas);
|
|
9
10
|
this.state = { pages: {}, rendering: false };
|
|
10
11
|
// Render pages using an offscreen canvas to avoid flickering that can occur for
|
|
11
12
|
// PDFs with annotations.
|
|
12
|
-
this.offscreenCanvas =
|
|
13
|
+
this.offscreenCanvas = createElement('canvas');
|
|
13
14
|
this.handleStateChanged = this.handleStateChanged.bind(this);
|
|
14
15
|
this.stateChangedDisposable = this.api.onStateChanged(this.handleStateChanged);
|
|
15
16
|
}
|
|
@@ -51,10 +52,18 @@ export class PdfJsRenderer extends DocumentRenderer {
|
|
|
51
52
|
});
|
|
52
53
|
this.offscreenCanvas.width = this.canvas.width;
|
|
53
54
|
this.offscreenCanvas.height = this.canvas.height;
|
|
55
|
+
const offscreenCanvasCtx = this.offscreenCanvas.getContext('2d');
|
|
56
|
+
// Fill the offscreen canvas with a white background prior to rendering the page to give the content
|
|
57
|
+
// of the PDF a white background, but maintain the canvas it gets drawn to when copying to the main canvas.
|
|
58
|
+
if (offscreenCanvasCtx != null) {
|
|
59
|
+
offscreenCanvasCtx.fillStyle = '#ffffff';
|
|
60
|
+
offscreenCanvasCtx.fillRect(panOffset.x + centerOffsetX, panOffset.y, scaled.width, scaled.height);
|
|
61
|
+
}
|
|
54
62
|
await page.render({
|
|
55
63
|
canvas: this.offscreenCanvas,
|
|
56
64
|
viewport: scaled,
|
|
57
65
|
intent: 'display',
|
|
66
|
+
background: 'transparent',
|
|
58
67
|
optionalContentConfigPromise: optionalContentConfig != null ? Promise.resolve(optionalContentConfig) : undefined,
|
|
59
68
|
}).promise;
|
|
60
69
|
// Emit an event before the page is drawn, then draw the page to the canvas on the next
|