Compare commits

..

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

View File

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