Skip to content

Commit 122822a

Browse files
committed
Simplify the loadXfaImages method and related code
Currently we create an intermediate `Dict` during parsing, however that seems unnecessary since (note especially the second point): - The `NameOrNumberTree.prototype.getAll` method will already resolve any references, as needed, during parsing. - The `Catalog.prototype.xfaImages` getter is invoked, via the `BasePdfManager`-instance, such that any `MissingDataException`s are already handled correctly.
1 parent 91bfe12 commit 122822a

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

src/core/catalog.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,13 @@ class Catalog {
10621062
if (obj instanceof Dict && obj.has("XFAImages")) {
10631063
const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
10641064
for (const [key, value] of nameTree.getAll()) {
1065-
xfaImages ??= new Dict(this.xref);
1066-
xfaImages.set(
1067-
stringToPDFString(key, /* keepEscapeSequence = */ true),
1068-
value
1069-
);
1065+
if (value instanceof BaseStream) {
1066+
xfaImages ??= new Map();
1067+
xfaImages.set(
1068+
stringToPDFString(key, /* keepEscapeSequence = */ true),
1069+
value.getBytes()
1070+
);
1071+
}
10701072
}
10711073
}
10721074
return shadow(this, "xfaImages", xfaImages);

src/core/document.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,23 +1238,10 @@ class PDFDocument {
12381238
}
12391239

12401240
async loadXfaImages() {
1241-
const xfaImagesDict = await this.pdfManager.ensureCatalog("xfaImages");
1242-
if (!xfaImagesDict) {
1241+
const xfaImages = await this.pdfManager.ensureCatalog("xfaImages");
1242+
if (!xfaImages) {
12431243
return;
12441244
}
1245-
1246-
const keys = xfaImagesDict.getKeys();
1247-
const objectLoader = new ObjectLoader(xfaImagesDict, keys, this.xref);
1248-
await objectLoader.load();
1249-
1250-
const xfaImages = new Map();
1251-
for (const key of keys) {
1252-
const stream = xfaImagesDict.get(key);
1253-
if (stream instanceof BaseStream) {
1254-
xfaImages.set(key, stream.getBytes());
1255-
}
1256-
}
1257-
12581245
this.xfaFactory.setImages(xfaImages);
12591246
}
12601247

src/core/xfa/template.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,8 +3412,7 @@ class Image extends StringObject {
34123412
return HTMLResult.EMPTY;
34133413
}
34143414

3415-
let buffer =
3416-
this[$globalData].images && this[$globalData].images.get(this.href);
3415+
let buffer = this[$globalData].images?.get(this.href);
34173416
if (!buffer && (this.href || !this[$content])) {
34183417
// In general, we don't get remote data and use what we have
34193418
// in the pdf itself, so no picture for non null href.

0 commit comments

Comments
 (0)