xfa_layer_builder.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_link_service = require("./pdf_link_service.js");
  28. var _pdf = require("../pdf");
  29. class XfaLayerBuilder {
  30. constructor({
  31. pageDiv,
  32. pdfPage,
  33. annotationStorage,
  34. linkService,
  35. xfaHtml
  36. }) {
  37. this.pageDiv = pageDiv;
  38. this.pdfPage = pdfPage;
  39. this.annotationStorage = annotationStorage;
  40. this.linkService = linkService;
  41. this.xfaHtml = xfaHtml;
  42. this.div = null;
  43. this._cancelled = false;
  44. }
  45. render(viewport, intent = "display") {
  46. if (intent === "print") {
  47. const parameters = {
  48. viewport: viewport.clone({
  49. dontFlip: true
  50. }),
  51. div: this.div,
  52. xfa: this.xfaHtml,
  53. page: null,
  54. annotationStorage: this.annotationStorage,
  55. linkService: this.linkService,
  56. intent
  57. };
  58. const div = document.createElement("div");
  59. this.pageDiv.appendChild(div);
  60. parameters.div = div;
  61. const result = _pdf.XfaLayer.render(parameters);
  62. return Promise.resolve(result);
  63. }
  64. return this.pdfPage.getXfa().then(xfa => {
  65. if (this._cancelled || !xfa) {
  66. return {
  67. textDivs: []
  68. };
  69. }
  70. const parameters = {
  71. viewport: viewport.clone({
  72. dontFlip: true
  73. }),
  74. div: this.div,
  75. xfa,
  76. page: this.pdfPage,
  77. annotationStorage: this.annotationStorage,
  78. linkService: this.linkService,
  79. intent
  80. };
  81. if (this.div) {
  82. return _pdf.XfaLayer.update(parameters);
  83. }
  84. this.div = document.createElement("div");
  85. this.pageDiv.appendChild(this.div);
  86. parameters.div = this.div;
  87. return _pdf.XfaLayer.render(parameters);
  88. }).catch(error => {
  89. console.error(error);
  90. });
  91. }
  92. cancel() {
  93. this._cancelled = true;
  94. }
  95. hide() {
  96. if (!this.div) {
  97. return;
  98. }
  99. this.div.hidden = true;
  100. }
  101. }
  102. exports.XfaLayerBuilder = XfaLayerBuilder;
  103. class DefaultXfaLayerFactory {
  104. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null, xfaHtml = null) {
  105. return new XfaLayerBuilder({
  106. pageDiv,
  107. pdfPage,
  108. annotationStorage,
  109. linkService: new _pdf_link_service.SimpleLinkService(),
  110. xfaHtml
  111. });
  112. }
  113. }
  114. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;