Compare commits

..

No commits in common. "00e3a4d87a22d92938687f7535bc35961a2a40e3" and "6243afa85e4639da6435c075913512f6bfbdd291" have entirely different histories.

View File

@ -251,9 +251,8 @@ class Page {
/**
* @returns {Promise<BaseStream>}
*/
async getContentStream() {
const content = await this.pdfManager.ensure(this, "content");
getContentStream() {
return this.pdfManager.ensure(this, "content").then(content => {
if (content instanceof BaseStream) {
return content;
}
@ -265,6 +264,7 @@ class Page {
}
// Replace non-existent page content with empty content.
return new NullStream();
});
}
get xfaData() {
@ -375,7 +375,7 @@ class Page {
}
}
async save(handler, task, annotationStorage, changes) {
save(handler, task, annotationStorage, changes) {
const partialEvaluator = new PartialEvaluator({
xref: this.xref,
handler,
@ -392,8 +392,7 @@ class Page {
// Fetch the page's annotations and save the content
// in case of interactive form fields.
const annotations = await this._parsedAnnotations;
return this._parsedAnnotations.then(function (annotations) {
const promises = [];
for (const annotation of annotations) {
promises.push(
@ -408,18 +407,22 @@ class Page {
})
);
}
return Promise.all(promises);
});
}
async loadResources(keys) {
loadResources(keys) {
// TODO: add async `_getInheritableProperty` and remove this.
await (this.resourcesPromise ??= this.pdfManager.ensure(this, "resources"));
this.resourcesPromise ||= this.pdfManager.ensure(this, "resources");
return this.resourcesPromise.then(() => {
const objectLoader = new ObjectLoader(this.resources, keys, this.xref);
await objectLoader.load();
return objectLoader.load();
});
}
async getOperatorList({
getOperatorList({
handler,
sink,
task,
@ -524,7 +527,7 @@ class Page {
const pageListPromise = Promise.all([
contentStreamPromise,
resourcesPromise,
]).then(async ([contentStream]) => {
]).then(([contentStream]) => {
const opList = new OperatorList(intent, sink);
handler.send("StartRenderPage", {
@ -536,27 +539,27 @@ class Page {
cacheKey,
});
await partialEvaluator.getOperatorList({
return partialEvaluator
.getOperatorList({
stream: contentStream,
task,
resources: this.resources,
operatorList: opList,
});
return opList;
})
.then(() => opList);
});
// Fetch the page's annotations and add their operator lists to the
// page's operator list to render them.
// eslint-disable-next-line prefer-const
let [pageOpList, annotations, newAnnotations] = await Promise.all([
return Promise.all([
pageListPromise,
this._parsedAnnotations,
newAnnotationsPromise,
]);
]).then(function ([pageOpList, annotations, newAnnotations]) {
if (newAnnotations) {
// Some annotations can already exist (if it has the refToReplace
// property). In this case, we replace the old annotation by the new one.
// property). In this case, we replace the old annotation by the new
// one.
annotations = annotations.filter(
a => !(a.ref && deletedAnnotations.has(a.ref))
);
@ -601,7 +604,12 @@ class Page {
) {
opListPromises.push(
annotation
.getOperatorList(partialEvaluator, task, intent, annotationStorage)
.getOperatorList(
partialEvaluator,
task,
intent,
annotationStorage
)
.catch(function (reason) {
warn(
"getOperatorList - ignoring annotation data during " +
@ -617,7 +625,7 @@ class Page {
}
}
const opLists = await Promise.all(opListPromises);
return Promise.all(opListPromises).then(function (opLists) {
let form = false,
canvas = false;
@ -632,6 +640,8 @@ class Page {
/* separateAnnots = */ { form, canvas }
);
return { length: pageOpList.totalLength };
});
});
}
async extractTextContent({