print_utils.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Copyright 2021 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. import { getXfaPageViewport, PixelsPerInch } from "pdfjs-lib";
  16. import { SimpleLinkService } from "./pdf_link_service.js";
  17. import { XfaLayerBuilder } from "./xfa_layer_builder.js";
  18. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  19. const xfaHtml = pdfDocument.allXfaHtml;
  20. const linkService = new SimpleLinkService();
  21. const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  22. for (const xfaPage of xfaHtml.children) {
  23. const page = document.createElement("div");
  24. page.className = "xfaPrintedPage";
  25. printContainer.append(page);
  26. const builder = new XfaLayerBuilder({
  27. pageDiv: page,
  28. pdfPage: null,
  29. annotationStorage: pdfDocument.annotationStorage,
  30. linkService,
  31. xfaHtml: xfaPage,
  32. });
  33. const viewport = getXfaPageViewport(xfaPage, { scale });
  34. builder.render(viewport, "print");
  35. }
  36. }
  37. export { getXfaHtmlForPrinting };