UNPKG

2.75 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * JavaScript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.XfaLayerBuilder = void 0;
28
29var _pdf = require("../pdf");
30
31class XfaLayerBuilder {
32 constructor({
33 pageDiv,
34 pdfPage,
35 annotationStorage = null,
36 linkService,
37 xfaHtml = null
38 }) {
39 this.pageDiv = pageDiv;
40 this.pdfPage = pdfPage;
41 this.annotationStorage = annotationStorage;
42 this.linkService = linkService;
43 this.xfaHtml = xfaHtml;
44 this.div = null;
45 this._cancelled = false;
46 }
47
48 render(viewport, intent = "display") {
49 if (intent === "print") {
50 const parameters = {
51 viewport: viewport.clone({
52 dontFlip: true
53 }),
54 div: this.div,
55 xfaHtml: this.xfaHtml,
56 annotationStorage: this.annotationStorage,
57 linkService: this.linkService,
58 intent
59 };
60 const div = document.createElement("div");
61 this.pageDiv.append(div);
62 parameters.div = div;
63
64 const result = _pdf.XfaLayer.render(parameters);
65
66 return Promise.resolve(result);
67 }
68
69 return this.pdfPage.getXfa().then(xfaHtml => {
70 if (this._cancelled || !xfaHtml) {
71 return {
72 textDivs: []
73 };
74 }
75
76 const parameters = {
77 viewport: viewport.clone({
78 dontFlip: true
79 }),
80 div: this.div,
81 xfaHtml,
82 annotationStorage: this.annotationStorage,
83 linkService: this.linkService,
84 intent
85 };
86
87 if (this.div) {
88 return _pdf.XfaLayer.update(parameters);
89 }
90
91 this.div = document.createElement("div");
92 this.pageDiv.append(this.div);
93 parameters.div = this.div;
94 return _pdf.XfaLayer.render(parameters);
95 }).catch(error => {
96 console.error(error);
97 });
98 }
99
100 cancel() {
101 this._cancelled = true;
102 }
103
104 hide() {
105 if (!this.div) {
106 return;
107 }
108
109 this.div.hidden = true;
110 }
111
112}
113
114exports.XfaLayerBuilder = XfaLayerBuilder;
\No newline at end of file