Skip to content

Commit

Permalink
Enable XFA by default in the viewer, and components/ examples (issu…
Browse files Browse the repository at this point in the history
…e 13968)

Given that https://bugzilla.mozilla.org/show_bug.cgi?id=1727396 has now landed, it should now be OK to make this change.
  • Loading branch information
Snuffleupagus committed Sep 14, 2021
1 parent 064c21d commit 7498b97
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
11 changes: 9 additions & 2 deletions examples/components/pageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const PAGE_TO_VIEW = 1;
const SCALE = 1.0;

const ENABLE_XFA = true;

const container = document.getElementById("pageContainer");

const eventBus = new pdfjsViewer.EventBus();
Expand All @@ -43,6 +45,7 @@ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
});
loadingTask.promise.then(function (pdfDocument) {
// Document loaded, retrieving the page.
Expand All @@ -55,9 +58,13 @@ loadingTask.promise.then(function (pdfDocument) {
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
eventBus,
// 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(),
xfaLayerFactory: new pdfjsViewer.DefaultXfaLayerFactory(),
xfaLayerFactory: pdfDocument.isPureXfa
? new pdfjsViewer.DefaultXfaLayerFactory()
: null,
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
});
// Associate the actual page with the view, and draw it.
Expand Down
7 changes: 5 additions & 2 deletions examples/components/simpleviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ const CMAP_PACKED = true;

const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
// 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 container = document.getElementById("viewerContainer");
Expand Down Expand Up @@ -84,6 +86,7 @@ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
});
loadingTask.promise.then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and
Expand Down
7 changes: 5 additions & 2 deletions examples/components/singlepageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ const CMAP_PACKED = true;

const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
// 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 container = document.getElementById("viewerContainer");
Expand Down Expand Up @@ -84,6 +86,7 @@ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
});
loadingTask.promise.then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and
Expand Down
2 changes: 1 addition & 1 deletion extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
},
"enableXfa": {
"type": "boolean",
"default": false
"default": true
},
"historyUpdateUrl": {
"type": "boolean",
Expand Down
9 changes: 4 additions & 5 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ const OptionKind = {
};

/**
* PLEASE NOTE: To avoid introducing unnecessary dependencies, we specify the
* values below *explicitly* rather than relying on imported types.
* NOTE: These options are used to generate the `default_preferences.json` file,
* see `OptionKind.PREFERENCE`, hence the values below must use only
* primitive types and cannot rely on any imported types.
*/
const defaultOptions = {
annotationMode: {
Expand Down Expand Up @@ -226,9 +227,7 @@ const defaultOptions = {
},
enableXfa: {
/** @type {boolean} */
value:
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING"),
value: true,
kind: OptionKind.API + OptionKind.PREFERENCE,
},
fontExtraProperties: {
Expand Down
1 change: 1 addition & 0 deletions web/text_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class DefaultTextLayerFactory {
viewport,
enhanceTextSelection,
eventBus,
highlighter,
});
}
}
Expand Down

0 comments on commit 7498b97

Please sign in to comment.