[Annotations] Some annotations can have their values stored in the xfa:datasets

- it aims to fix #14685;
- add a basic object to get values from the parsed datasets;
- these annotations don't have an appearance so we must create one when printing or saving.
This commit is contained in:
Calixte Denizet 2022-03-31 19:18:30 +02:00
parent d6592b5e37
commit 0b597304c1
6 changed files with 178 additions and 13 deletions

View file

@ -47,6 +47,7 @@ import { BaseStream } from "./base_stream.js";
import { calculateMD5 } from "./crypto.js";
import { Catalog } from "./catalog.js";
import { clearGlobalCaches } from "./cleanup_helper.js";
import { DatasetReader } from "./dataset_reader.js";
import { Linearization } from "./parser.js";
import { NullStream } from "./stream.js";
import { ObjectLoader } from "./object_loader.js";
@ -820,6 +821,47 @@ class PDFDocument {
});
}
get xfaDatasets() {
const acroForm = this.catalog.acroForm;
if (!acroForm) {
return shadow(this, "xfaDatasets", null);
}
const xfa = acroForm.get("XFA");
if (xfa instanceof BaseStream && !xfa.isEmpty) {
try {
const xdp = stringToUTF8String(xfa.getString());
return shadow(this, "xfaDatasets", new DatasetReader({ xdp }));
} catch (_) {
warn("XFA - Invalid utf-8 string.");
return shadow(this, "xfaDatasets", null);
}
}
if (!Array.isArray(xfa) || xfa.length === 0) {
return null;
}
for (let i = 0, ii = xfa.length; i < ii; i += 2) {
if (xfa[i] !== "datasets") {
continue;
}
const data = this.xref.fetchIfRef(xfa[i + 1]);
if (!(data instanceof BaseStream) || data.isEmpty) {
continue;
}
try {
const datasets = stringToUTF8String(data.getString());
return shadow(this, "xfaDatasets", new DatasetReader({ datasets }));
} catch (_) {
warn("XFA - Invalid utf-8 string.");
return shadow(this, "xfaDatasets", null);
}
}
return shadow(this, "xfaDatasets", null);
}
get xfaData() {
const acroForm = this.catalog.acroForm;
if (!acroForm) {