xfa_layer_builder.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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 = exports.DefaultXfaLayerFactory = void 0;
  27. var _pdf = require("../pdf");
  28. class XfaLayerBuilder {
  29. constructor({
  30. pageDiv,
  31. pdfPage,
  32. xfaHtml,
  33. annotationStorage
  34. }) {
  35. this.pageDiv = pageDiv;
  36. this.pdfPage = pdfPage;
  37. this.xfaHtml = xfaHtml;
  38. this.annotationStorage = annotationStorage;
  39. this.div = null;
  40. this._cancelled = false;
  41. }
  42. render(viewport, intent = "display") {
  43. if (intent === "print") {
  44. const parameters = {
  45. viewport: viewport.clone({
  46. dontFlip: true
  47. }),
  48. div: this.div,
  49. xfa: this.xfaHtml,
  50. page: null,
  51. annotationStorage: this.annotationStorage,
  52. intent
  53. };
  54. const div = document.createElement("div");
  55. this.pageDiv.appendChild(div);
  56. parameters.div = div;
  57. _pdf.XfaLayer.render(parameters);
  58. return Promise.resolve();
  59. }
  60. return this.pdfPage.getXfa().then(xfa => {
  61. if (this._cancelled) {
  62. return;
  63. }
  64. const parameters = {
  65. viewport: viewport.clone({
  66. dontFlip: true
  67. }),
  68. div: this.div,
  69. xfa,
  70. page: this.pdfPage,
  71. annotationStorage: this.annotationStorage,
  72. intent
  73. };
  74. if (this.div) {
  75. _pdf.XfaLayer.update(parameters);
  76. } else {
  77. this.div = document.createElement("div");
  78. this.pageDiv.appendChild(this.div);
  79. parameters.div = this.div;
  80. _pdf.XfaLayer.render(parameters);
  81. }
  82. }).catch(error => {
  83. console.error(error);
  84. });
  85. }
  86. cancel() {
  87. this._cancelled = true;
  88. }
  89. hide() {
  90. if (!this.div) {
  91. return;
  92. }
  93. this.div.hidden = true;
  94. }
  95. }
  96. exports.XfaLayerBuilder = XfaLayerBuilder;
  97. class DefaultXfaLayerFactory {
  98. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null, xfaHtml = null) {
  99. return new XfaLayerBuilder({
  100. pageDiv,
  101. pdfPage,
  102. annotationStorage,
  103. xfaHtml
  104. });
  105. }
  106. }
  107. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;