Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the entire PDF document is loaded *before* we begin saving it #16941

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down