mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
[Editor] Add support for printing newly added Ink annotations
This commit is contained in:
parent
8d466f5dac
commit
f27c8c4471
6 changed files with 271 additions and 94 deletions
|
@ -15,7 +15,6 @@
|
|||
|
||||
import {
|
||||
AbortException,
|
||||
AnnotationEditorPrefix,
|
||||
arrayByteLength,
|
||||
arraysToBytes,
|
||||
createPromiseCapability,
|
||||
|
@ -33,13 +32,13 @@ import {
|
|||
warn,
|
||||
} from "../shared/util.js";
|
||||
import { Dict, Ref } from "./primitives.js";
|
||||
import { getNewAnnotationsMap, XRefParseException } from "./core_utils.js";
|
||||
import { LocalPdfManager, NetworkPdfManager } from "./pdf_manager.js";
|
||||
import { clearGlobalCaches } from "./cleanup_helper.js";
|
||||
import { incrementalUpdate } from "./writer.js";
|
||||
import { isNodeJS } from "../shared/is_node.js";
|
||||
import { MessageHandler } from "../shared/message_handler.js";
|
||||
import { PDFWorkerStream } from "./worker_stream.js";
|
||||
import { XRefParseException } from "./core_utils.js";
|
||||
|
||||
class WorkerTask {
|
||||
constructor(name) {
|
||||
|
@ -558,22 +557,9 @@ 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 newAnnotationsByPage = !isPureXfa
|
||||
? getNewAnnotationsMap(annotationStorage)
|
||||
: null;
|
||||
|
||||
const promises = [
|
||||
pdfManager.onLoadedStream(),
|
||||
|
@ -583,17 +569,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 (newAnnotationsByPage) {
|
||||
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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue