mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08: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
|
@ -55,6 +55,7 @@ import { OperatorList } from "./operator_list.js";
|
|||
import { PartialEvaluator } from "./evaluator.js";
|
||||
import { StreamsSequenceStream } from "./decode_stream.js";
|
||||
import { StructTreePage } from "./struct_tree.js";
|
||||
import { writeObject } from "./writer.js";
|
||||
import { XFAFactory } from "./xfa/factory.js";
|
||||
import { XRef } from "./xref.js";
|
||||
|
||||
|
@ -261,6 +262,60 @@ class Page {
|
|||
);
|
||||
}
|
||||
|
||||
async saveNewAnnotations(handler, task, annotations) {
|
||||
if (this.xfaFactory) {
|
||||
throw new Error("XFA: Cannot save new annotations.");
|
||||
}
|
||||
|
||||
const partialEvaluator = new PartialEvaluator({
|
||||
xref: this.xref,
|
||||
handler,
|
||||
pageIndex: this.pageIndex,
|
||||
idFactory: this._localIdFactory,
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
options: this.evaluatorOptions,
|
||||
});
|
||||
|
||||
const pageDict = this.pageDict;
|
||||
const annotationsArray = this.annotations.slice();
|
||||
const newData = await AnnotationFactory.saveNewAnnotations(
|
||||
partialEvaluator,
|
||||
task,
|
||||
annotations
|
||||
);
|
||||
|
||||
for (const { ref } of newData.annotations) {
|
||||
annotationsArray.push(ref);
|
||||
}
|
||||
|
||||
const savedDict = pageDict.get("Annots");
|
||||
pageDict.set("Annots", annotationsArray);
|
||||
const buffer = [];
|
||||
|
||||
let transform = null;
|
||||
if (this.xref.encrypt) {
|
||||
transform = this.xref.encrypt.createCipherTransform(
|
||||
this.ref.num,
|
||||
this.ref.gen
|
||||
);
|
||||
}
|
||||
|
||||
writeObject(this.ref, pageDict, buffer, transform);
|
||||
if (savedDict) {
|
||||
pageDict.set("Annots", savedDict);
|
||||
}
|
||||
|
||||
const objects = newData.dependencies;
|
||||
objects.push(
|
||||
{ ref: this.ref, data: buffer.join("") },
|
||||
...newData.annotations
|
||||
);
|
||||
return objects;
|
||||
}
|
||||
|
||||
save(handler, task, annotationStorage) {
|
||||
const partialEvaluator = new PartialEvaluator({
|
||||
xref: this.xref,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue