xfa_layer_builder.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. }) {
  33. this.pageDiv = pageDiv;
  34. this.pdfPage = pdfPage;
  35. this.div = null;
  36. this._cancelled = false;
  37. }
  38. render(viewport, intent = "display") {
  39. return this.pdfPage.getXfa().then(xfa => {
  40. if (this._cancelled) {
  41. return;
  42. }
  43. const parameters = {
  44. viewport: viewport.clone({
  45. dontFlip: true
  46. }),
  47. div: this.div,
  48. xfa,
  49. page: this.pdfPage
  50. };
  51. if (this.div) {
  52. _pdf.XfaLayer.update(parameters);
  53. } else {
  54. this.div = document.createElement("div");
  55. this.pageDiv.appendChild(this.div);
  56. parameters.div = this.div;
  57. _pdf.XfaLayer.render(parameters);
  58. }
  59. });
  60. }
  61. cancel() {
  62. this._cancelled = true;
  63. }
  64. hide() {
  65. if (!this.div) {
  66. return;
  67. }
  68. this.div.hidden = true;
  69. }
  70. }
  71. exports.XfaLayerBuilder = XfaLayerBuilder;
  72. class DefaultXfaLayerFactory {
  73. createXfaLayerBuilder(pageDiv, pdfPage) {
  74. return new XfaLayerBuilder({
  75. pageDiv,
  76. pdfPage
  77. });
  78. }
  79. }
  80. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;