Merge pull request #16941 from Snuffleupagus/SaveDocument-await-requestLoadedStream

Ensure that the entire PDF document is loaded *before* we begin saving it
This commit is contained in:
Jonas Jenwald 2023-09-12 17:34:34 +02:00 committed by GitHub
commit b1578225fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -535,19 +535,21 @@ class WorkerMessageHandler {
handler.on( handler.on(
"SaveDocument", "SaveDocument",
async function ({ isPureXfa, numPages, annotationStorage, filename }) { async function ({ isPureXfa, numPages, annotationStorage, filename }) {
const promises = [ const globalPromises = [
pdfManager.requestLoadedStream(), pdfManager.requestLoadedStream(),
pdfManager.ensureCatalog("acroForm"), pdfManager.ensureCatalog("acroForm"),
pdfManager.ensureCatalog("acroFormRef"), pdfManager.ensureCatalog("acroFormRef"),
pdfManager.ensureDoc("startXRef"), pdfManager.ensureDoc("startXRef"),
pdfManager.ensureDoc("xref"),
pdfManager.ensureDoc("linearization"), pdfManager.ensureDoc("linearization"),
]; ];
const promises = [];
const newAnnotationsByPage = !isPureXfa const newAnnotationsByPage = !isPureXfa
? getNewAnnotationsMap(annotationStorage) ? getNewAnnotationsMap(annotationStorage)
: null; : null;
const [stream, acroForm, acroFormRef, startXRef, xref, linearization] =
const xref = await pdfManager.ensureDoc("xref"); await Promise.all(globalPromises);
if (newAnnotationsByPage) { if (newAnnotationsByPage) {
const imagePromises = AnnotationFactory.generateImages( const imagePromises = AnnotationFactory.generateImages(
@ -587,14 +589,7 @@ class WorkerMessageHandler {
} }
} }
return Promise.all(promises).then(function ([ return Promise.all(promises).then(refs => {
stream,
acroForm,
acroFormRef,
startXRef,
linearization,
...refs
]) {
let newRefs = []; let newRefs = [];
let xfaData = null; let xfaData = null;
if (isPureXfa) { if (isPureXfa) {