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

Handle WorkerTasks, and various PDF document properties, correctly in the "SaveDocument" handler in src/core/worker.js #12477

Merged
merged 1 commit into from
Oct 13, 2020
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
31 changes: 22 additions & 9 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,32 @@ class WorkerMessageHandler {
const promises = [
pdfManager.onLoadedStream(),
pdfManager.ensureCatalog("acroForm"),
pdfManager.ensureDoc("xref"),
pdfManager.ensureDoc("startXRef"),
];
const document = pdfManager.pdfDocument;

for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
promises.push(
pdfManager.getPage(pageIndex).then(function (page) {
const task = new WorkerTask(`Save: page ${pageIndex}`);
return page.save(handler, task, annotationStorage);
startWorkerTask(task);

return page
.save(handler, task, annotationStorage)
.finally(function () {
finishWorkerTask(task);
});
})
);
}

return Promise.all(promises).then(([stream, acroForm, ...refs]) => {
return Promise.all(promises).then(function ([
stream,
acroForm,
xref,
startXRef,
...refs
]) {
let newRefs = [];
for (const ref of refs) {
newRefs = ref
Expand All @@ -562,16 +576,15 @@ class WorkerMessageHandler {
warn("Unsupported XFA type.");
}

const xref = document.xref;
let newXrefInfo = Object.create(null);
if (xref.trailer) {
// Get string info from Info in order to compute fileId
const _info = Object.create(null);
// Get string info from Info in order to compute fileId.
const infoObj = Object.create(null);
const xrefInfo = xref.trailer.get("Info") || null;
if (xrefInfo instanceof Dict) {
xrefInfo.forEach((key, value) => {
if (isString(key) && isString(value)) {
_info[key] = stringToPDFString(value);
infoObj[key] = stringToPDFString(value);
}
});
}
Expand All @@ -581,9 +594,9 @@ class WorkerMessageHandler {
encrypt: xref.trailer.getRaw("Encrypt") || null,
newRef: xref.getNewRef(),
infoRef: xref.trailer.getRaw("Info") || null,
info: _info,
info: infoObj,
fileIds: xref.trailer.getRaw("ID") || null,
startXRef: document.startXRef,
startXRef,
filename,
};
}
Expand Down