Enable XFA by default in the viewer, and components/ examples (issue 13968)

Given that https://bugzilla.mozilla.org/show_bug.cgi?id=1727396 has now landed, it should now be OK to make this change.
This commit is contained in:
Jonas Jenwald 2021-09-08 12:33:59 +02:00
parent 064c21d360
commit 7498b97aaa
6 changed files with 25 additions and 12 deletions

View File

@ -34,6 +34,8 @@ const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const PAGE_TO_VIEW = 1; const PAGE_TO_VIEW = 1;
const SCALE = 1.0; const SCALE = 1.0;
const ENABLE_XFA = true;
const container = document.getElementById("pageContainer"); const container = document.getElementById("pageContainer");
const eventBus = new pdfjsViewer.EventBus(); const eventBus = new pdfjsViewer.EventBus();
@ -43,6 +45,7 @@ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL, url: DEFAULT_URL,
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
}); });
loadingTask.promise.then(function (pdfDocument) { loadingTask.promise.then(function (pdfDocument) {
// Document loaded, retrieving the page. // Document loaded, retrieving the page.
@ -55,9 +58,13 @@ loadingTask.promise.then(function (pdfDocument) {
defaultViewport: pdfPage.getViewport({ scale: SCALE }), defaultViewport: pdfPage.getViewport({ scale: SCALE }),
eventBus, eventBus,
// We can enable text/annotation/xfa/struct-layers, as needed. // We can enable text/annotation/xfa/struct-layers, as needed.
textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory(), textLayerFactory: !pdfDocument.isPureXfa
? new pdfjsViewer.DefaultTextLayerFactory()
: null,
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(), annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
xfaLayerFactory: new pdfjsViewer.DefaultXfaLayerFactory(), xfaLayerFactory: pdfDocument.isPureXfa
? new pdfjsViewer.DefaultXfaLayerFactory()
: null,
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(), structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
}); });
// Associate the actual page with the view, and draw it. // Associate the actual page with the view, and draw it.

View File

@ -32,9 +32,11 @@ const CMAP_PACKED = true;
const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
// To test the AcroForm and/or scripting functionality, try e.g. this file: // To test the AcroForm and/or scripting functionality, try e.g. this file:
// var DEFAULT_URL = "../../test/pdfs/160F-2019.pdf"; // "../../test/pdfs/160F-2019.pdf"
const ENABLE_XFA = true;
const SEARCH_FOR = ""; // try "Mozilla";
const SEARCH_FOR = ""; // try 'Mozilla';
const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js"; const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js";
const container = document.getElementById("viewerContainer"); const container = document.getElementById("viewerContainer");
@ -84,6 +86,7 @@ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL, url: DEFAULT_URL,
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
}); });
loadingTask.promise.then(function (pdfDocument) { loadingTask.promise.then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and // Document loaded, specifying document for the viewer and

View File

@ -32,9 +32,11 @@ const CMAP_PACKED = true;
const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
// To test the AcroForm and/or scripting functionality, try e.g. this file: // To test the AcroForm and/or scripting functionality, try e.g. this file:
// var DEFAULT_URL = "../../test/pdfs/160F-2019.pdf"; // "../../test/pdfs/160F-2019.pdf"
const ENABLE_XFA = true;
const SEARCH_FOR = ""; // try "Mozilla";
const SEARCH_FOR = ""; // try 'Mozilla';
const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js"; const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js";
const container = document.getElementById("viewerContainer"); const container = document.getElementById("viewerContainer");
@ -84,6 +86,7 @@ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL, url: DEFAULT_URL,
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
}); });
loadingTask.promise.then(function (pdfDocument) { loadingTask.promise.then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and // Document loaded, specifying document for the viewer and

View File

@ -166,7 +166,7 @@
}, },
"enableXfa": { "enableXfa": {
"type": "boolean", "type": "boolean",
"default": false "default": true
}, },
"historyUpdateUrl": { "historyUpdateUrl": {
"type": "boolean", "type": "boolean",

View File

@ -55,8 +55,9 @@ const OptionKind = {
}; };
/** /**
* PLEASE NOTE: To avoid introducing unnecessary dependencies, we specify the * NOTE: These options are used to generate the `default_preferences.json` file,
* values below *explicitly* rather than relying on imported types. * see `OptionKind.PREFERENCE`, hence the values below must use only
* primitive types and cannot rely on any imported types.
*/ */
const defaultOptions = { const defaultOptions = {
annotationMode: { annotationMode: {
@ -226,9 +227,7 @@ const defaultOptions = {
}, },
enableXfa: { enableXfa: {
/** @type {boolean} */ /** @type {boolean} */
value: value: true,
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING"),
kind: OptionKind.API + OptionKind.PREFERENCE, kind: OptionKind.API + OptionKind.PREFERENCE,
}, },
fontExtraProperties: { fontExtraProperties: {

View File

@ -244,6 +244,7 @@ class DefaultTextLayerFactory {
viewport, viewport,
enhanceTextSelection, enhanceTextSelection,
eventBus, eventBus,
highlighter,
}); });
} }
} }