xfa_layer_builder.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.XfaLayerBuilder = void 0;
  27. var _pdf = require("../pdf");
  28. class XfaLayerBuilder {
  29. constructor({
  30. pageDiv,
  31. pdfPage,
  32. annotationStorage = null,
  33. linkService,
  34. xfaHtml = null
  35. }) {
  36. this.pageDiv = pageDiv;
  37. this.pdfPage = pdfPage;
  38. this.annotationStorage = annotationStorage;
  39. this.linkService = linkService;
  40. this.xfaHtml = xfaHtml;
  41. this.div = null;
  42. this._cancelled = false;
  43. }
  44. render(viewport, intent = "display") {
  45. if (intent === "print") {
  46. const parameters = {
  47. viewport: viewport.clone({
  48. dontFlip: true
  49. }),
  50. div: this.div,
  51. xfaHtml: this.xfaHtml,
  52. annotationStorage: this.annotationStorage,
  53. linkService: this.linkService,
  54. intent
  55. };
  56. const div = document.createElement("div");
  57. this.pageDiv.append(div);
  58. parameters.div = div;
  59. const result = _pdf.XfaLayer.render(parameters);
  60. return Promise.resolve(result);
  61. }
  62. return this.pdfPage.getXfa().then(xfaHtml => {
  63. if (this._cancelled || !xfaHtml) {
  64. return {
  65. textDivs: []
  66. };
  67. }
  68. const parameters = {
  69. viewport: viewport.clone({
  70. dontFlip: true
  71. }),
  72. div: this.div,
  73. xfaHtml,
  74. annotationStorage: this.annotationStorage,
  75. linkService: this.linkService,
  76. intent
  77. };
  78. if (this.div) {
  79. return _pdf.XfaLayer.update(parameters);
  80. }
  81. this.div = document.createElement("div");
  82. this.pageDiv.append(this.div);
  83. parameters.div = this.div;
  84. return _pdf.XfaLayer.render(parameters);
  85. }).catch(error => {
  86. console.error(error);
  87. });
  88. }
  89. cancel() {
  90. this._cancelled = true;
  91. }
  92. hide() {
  93. if (!this.div) {
  94. return;
  95. }
  96. this.div.hidden = true;
  97. }
  98. }
  99. exports.XfaLayerBuilder = XfaLayerBuilder;