XFA - Add support to print XFA forms

This commit is contained in:
Calixte Denizet 2021-05-27 16:56:31 +02:00
parent 8c53bf8647
commit a434011517
7 changed files with 130 additions and 35 deletions

View file

@ -13,6 +13,8 @@
* limitations under the License.
*/
import { DefaultXfaLayerFactory } from "./xfa_layer_builder.js";
const CSS_UNITS = 96.0 / 72.0;
const DEFAULT_SCALE_VALUE = "auto";
const DEFAULT_SCALE = 1.0;
@ -994,6 +996,29 @@ function apiPageModeToSidebarView(mode) {
return SidebarView.NONE; // Default value.
}
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.setAttribute("class", "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(
page,
null,
pdfDocument.annotationStorage,
xfaPage
);
builder.render(viewport, "print");
}
}
export {
animationStarted,
apiPageLayoutToSpreadMode,
@ -1010,6 +1035,7 @@ export {
getOutputScale,
getPageSizeInches,
getVisibleElements,
getXfaHtmlForPrinting,
isPortraitOrientation,
isValidRotation,
isValidScrollMode,