1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[api-minor] Add a new getXfaPageViewport helper function to support printing

This patch provides an overall simpler *and* more consistent way of handling the `viewport` parameter during printing of XFA forms, since it's now again guaranteed to always be an instance of `PageViewport`.
Furthermore, for anyone attempting to e.g. implement custom printing of XFA forms this probably cannot hurt either.
This commit is contained in:
Jonas Jenwald 2021-06-18 12:31:58 +02:00
parent 45c1390c42
commit 87be43c193
6 changed files with 28 additions and 16 deletions

View file

@ -15,26 +15,26 @@
import { CSS_UNITS } from "./ui_utils.js";
import { DefaultXfaLayerFactory } from "./xfa_layer_builder.js";
import { getXfaPageViewport } from "pdfjs-lib";
function getXfaHtmlForPrinting(printContainer, pdfDocument) {
const xfaHtml = pdfDocument.allXfaHtml;
const factory = new DefaultXfaLayerFactory();
const scale = Math.round(CSS_UNITS * 100) / 100;
for (const xfaPage of xfaHtml.children) {
const page = document.createElement("div");
page.className = "xfaPrintedPage";
printContainer.appendChild(page);
const { width, height } = xfaPage.attributes.style;
const viewBox = [0, 0, parseInt(width), parseInt(height)];
const viewport = { viewBox, scale, rotation: 0 };
const builder = factory.createXfaLayerBuilder(
/* pageDiv = */ page,
/* pdfPage = */ null,
/* annotationStorage = */ pdfDocument.annotationStorage,
/* xfaHtml = */ xfaPage
);
const viewport = getXfaPageViewport(xfaPage, { scale });
builder.render(viewport, "print");
}
}

View file

@ -44,9 +44,8 @@ class XfaLayerBuilder {
*/
render(viewport, intent = "display") {
if (intent === "print") {
viewport.dontFlip = true;
const parameters = {
viewport,
viewport: viewport.clone({ dontFlip: true }),
div: this.div,
xfa: this.xfaHtml,
page: null,
@ -76,6 +75,7 @@ class XfaLayerBuilder {
xfa,
page: this.pdfPage,
annotationStorage: this.annotationStorage,
intent,
};
if (this.div) {