mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
[edition] Add support for saving a newly added FreeText
This commit is contained in:
parent
1816b5e926
commit
7773b3f5be
12 changed files with 409 additions and 23 deletions
|
@ -15,6 +15,7 @@
|
|||
|
||||
import {
|
||||
AbortException,
|
||||
AnnotationEditorPrefix,
|
||||
arrayByteLength,
|
||||
arraysToBytes,
|
||||
createPromiseCapability,
|
||||
|
@ -557,6 +558,23 @@ class WorkerMessageHandler {
|
|||
function ({ isPureXfa, numPages, annotationStorage, filename }) {
|
||||
pdfManager.requestLoadedStream();
|
||||
|
||||
const newAnnotationsByPage = new Map();
|
||||
if (!isPureXfa) {
|
||||
// The concept of page in a XFA is very different, so
|
||||
// editing is just not implemented.
|
||||
for (const [key, value] of annotationStorage) {
|
||||
if (!key.startsWith(AnnotationEditorPrefix)) {
|
||||
continue;
|
||||
}
|
||||
let annotations = newAnnotationsByPage.get(value.pageIndex);
|
||||
if (!annotations) {
|
||||
annotations = [];
|
||||
newAnnotationsByPage.set(value.pageIndex, annotations);
|
||||
}
|
||||
annotations.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
const promises = [
|
||||
pdfManager.onLoadedStream(),
|
||||
pdfManager.ensureCatalog("acroForm"),
|
||||
|
@ -565,6 +583,19 @@ class WorkerMessageHandler {
|
|||
pdfManager.ensureDoc("startXRef"),
|
||||
];
|
||||
|
||||
for (const [pageIndex, annotations] of newAnnotationsByPage) {
|
||||
promises.push(
|
||||
pdfManager.getPage(pageIndex).then(page => {
|
||||
const task = new WorkerTask(`Save (editor): page ${pageIndex}`);
|
||||
return page
|
||||
.saveNewAnnotations(handler, task, annotations)
|
||||
.finally(function () {
|
||||
finishWorkerTask(task);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isPureXfa) {
|
||||
promises.push(pdfManager.serializeXfaData(annotationStorage));
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue