Ensure that the entire PDF document is loaded *before* we begin saving it
When I started looking at PR 16938 it occurred to me that some of the new structTree-methods are synchronously accessing certain dictionary-data (not used during "normal" structTree-parsing), which may not be generally safe since everything in a dictionary could be a reference (and the relevant data may not have been loaded yet). Rather than suggesting that we make all those new methods even more asynchronous, to me the overall simplest and safest solution is to ensure that the *entire* PDF document has been loaded *before* we begin saving it. In practice this shouldn't really affect "performance" of saving noticeably, since it's always depended on the entire PDF document being downloaded. Finally note that with the exception of the PDF document possibly not having been fully downloaded when saving is triggered, all other "global" document properties are pretty much guaranteed to already be available at this point.
This commit is contained in:
parent
5f93638045
commit
50937a3539
@ -535,19 +535,21 @@ class WorkerMessageHandler {
|
||||
handler.on(
|
||||
"SaveDocument",
|
||||
async function ({ isPureXfa, numPages, annotationStorage, filename }) {
|
||||
const promises = [
|
||||
const globalPromises = [
|
||||
pdfManager.requestLoadedStream(),
|
||||
pdfManager.ensureCatalog("acroForm"),
|
||||
pdfManager.ensureCatalog("acroFormRef"),
|
||||
pdfManager.ensureDoc("startXRef"),
|
||||
pdfManager.ensureDoc("xref"),
|
||||
pdfManager.ensureDoc("linearization"),
|
||||
];
|
||||
const promises = [];
|
||||
|
||||
const newAnnotationsByPage = !isPureXfa
|
||||
? getNewAnnotationsMap(annotationStorage)
|
||||
: null;
|
||||
|
||||
const xref = await pdfManager.ensureDoc("xref");
|
||||
const [stream, acroForm, acroFormRef, startXRef, xref, linearization] =
|
||||
await Promise.all(globalPromises);
|
||||
|
||||
if (newAnnotationsByPage) {
|
||||
const imagePromises = AnnotationFactory.generateImages(
|
||||
@ -587,14 +589,7 @@ class WorkerMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(promises).then(function ([
|
||||
stream,
|
||||
acroForm,
|
||||
acroFormRef,
|
||||
startXRef,
|
||||
linearization,
|
||||
...refs
|
||||
]) {
|
||||
return Promise.all(promises).then(refs => {
|
||||
let newRefs = [];
|
||||
let xfaData = null;
|
||||
if (isPureXfa) {
|
||||
|
Loading…
Reference in New Issue
Block a user