Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/embedpre.../assets/pdf/build
File: pdf.worker.js
const buffer = [];
[41000] Fix | Delete
xml.documentElement.dump(buffer);
[41001] Fix | Delete
return buffer.join("");
[41002] Fix | Delete
}
[41003] Fix | Delete
async function updateAcroform({
[41004] Fix | Delete
xref,
[41005] Fix | Delete
acroForm,
[41006] Fix | Delete
acroFormRef,
[41007] Fix | Delete
hasXfa,
[41008] Fix | Delete
hasXfaDatasetsEntry,
[41009] Fix | Delete
xfaDatasetsRef,
[41010] Fix | Delete
needAppearances,
[41011] Fix | Delete
newRefs
[41012] Fix | Delete
}) {
[41013] Fix | Delete
if (hasXfa && !hasXfaDatasetsEntry && !xfaDatasetsRef) {
[41014] Fix | Delete
warn("XFA - Cannot save it");
[41015] Fix | Delete
}
[41016] Fix | Delete
if (!needAppearances && (!hasXfa || !xfaDatasetsRef || hasXfaDatasetsEntry)) {
[41017] Fix | Delete
return;
[41018] Fix | Delete
}
[41019] Fix | Delete
const dict = acroForm.clone();
[41020] Fix | Delete
if (hasXfa && !hasXfaDatasetsEntry) {
[41021] Fix | Delete
const newXfa = acroForm.get("XFA").slice();
[41022] Fix | Delete
newXfa.splice(2, 0, "datasets");
[41023] Fix | Delete
newXfa.splice(3, 0, xfaDatasetsRef);
[41024] Fix | Delete
dict.set("XFA", newXfa);
[41025] Fix | Delete
}
[41026] Fix | Delete
if (needAppearances) {
[41027] Fix | Delete
dict.set("NeedAppearances", true);
[41028] Fix | Delete
}
[41029] Fix | Delete
const buffer = [];
[41030] Fix | Delete
await writeObject(acroFormRef, dict, buffer, xref);
[41031] Fix | Delete
newRefs.push({
[41032] Fix | Delete
ref: acroFormRef,
[41033] Fix | Delete
data: buffer.join("")
[41034] Fix | Delete
});
[41035] Fix | Delete
}
[41036] Fix | Delete
function updateXFA({
[41037] Fix | Delete
xfaData,
[41038] Fix | Delete
xfaDatasetsRef,
[41039] Fix | Delete
newRefs,
[41040] Fix | Delete
xref
[41041] Fix | Delete
}) {
[41042] Fix | Delete
if (xfaData === null) {
[41043] Fix | Delete
const datasets = xref.fetchIfRef(xfaDatasetsRef);
[41044] Fix | Delete
xfaData = writeXFADataForAcroform(datasets.getString(), newRefs);
[41045] Fix | Delete
}
[41046] Fix | Delete
const encrypt = xref.encrypt;
[41047] Fix | Delete
if (encrypt) {
[41048] Fix | Delete
const transform = encrypt.createCipherTransform(xfaDatasetsRef.num, xfaDatasetsRef.gen);
[41049] Fix | Delete
xfaData = transform.encryptString(xfaData);
[41050] Fix | Delete
}
[41051] Fix | Delete
const data = `${xfaDatasetsRef.num} ${xfaDatasetsRef.gen} obj\n` + `<< /Type /EmbeddedFile /Length ${xfaData.length}>>\nstream\n` + xfaData + "\nendstream\nendobj\n";
[41052] Fix | Delete
newRefs.push({
[41053] Fix | Delete
ref: xfaDatasetsRef,
[41054] Fix | Delete
data
[41055] Fix | Delete
});
[41056] Fix | Delete
}
[41057] Fix | Delete
async function getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
[41058] Fix | Delete
buffer.push("xref\n");
[41059] Fix | Delete
const indexes = getIndexes(newRefs);
[41060] Fix | Delete
let indexesPosition = 0;
[41061] Fix | Delete
for (const {
[41062] Fix | Delete
ref,
[41063] Fix | Delete
data
[41064] Fix | Delete
} of newRefs) {
[41065] Fix | Delete
if (ref.num === indexes[indexesPosition]) {
[41066] Fix | Delete
buffer.push(`${indexes[indexesPosition]} ${indexes[indexesPosition + 1]}\n`);
[41067] Fix | Delete
indexesPosition += 2;
[41068] Fix | Delete
}
[41069] Fix | Delete
if (data !== null) {
[41070] Fix | Delete
buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`);
[41071] Fix | Delete
baseOffset += data.length;
[41072] Fix | Delete
} else {
[41073] Fix | Delete
buffer.push(`0000000000 ${Math.min(ref.gen + 1, 0xffff).toString().padStart(5, "0")} f\r\n`);
[41074] Fix | Delete
}
[41075] Fix | Delete
}
[41076] Fix | Delete
computeIDs(baseOffset, xrefInfo, newXref);
[41077] Fix | Delete
buffer.push("trailer\n");
[41078] Fix | Delete
await writeDict(newXref, buffer);
[41079] Fix | Delete
buffer.push("\nstartxref\n", baseOffset.toString(), "\n%%EOF\n");
[41080] Fix | Delete
}
[41081] Fix | Delete
function getIndexes(newRefs) {
[41082] Fix | Delete
const indexes = [];
[41083] Fix | Delete
for (const {
[41084] Fix | Delete
ref
[41085] Fix | Delete
} of newRefs) {
[41086] Fix | Delete
if (ref.num === indexes.at(-2) + indexes.at(-1)) {
[41087] Fix | Delete
indexes[indexes.length - 1] += 1;
[41088] Fix | Delete
} else {
[41089] Fix | Delete
indexes.push(ref.num, 1);
[41090] Fix | Delete
}
[41091] Fix | Delete
}
[41092] Fix | Delete
return indexes;
[41093] Fix | Delete
}
[41094] Fix | Delete
async function getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
[41095] Fix | Delete
const xrefTableData = [];
[41096] Fix | Delete
let maxOffset = 0;
[41097] Fix | Delete
let maxGen = 0;
[41098] Fix | Delete
for (const {
[41099] Fix | Delete
ref,
[41100] Fix | Delete
data
[41101] Fix | Delete
} of newRefs) {
[41102] Fix | Delete
let gen;
[41103] Fix | Delete
maxOffset = Math.max(maxOffset, baseOffset);
[41104] Fix | Delete
if (data !== null) {
[41105] Fix | Delete
gen = Math.min(ref.gen, 0xffff);
[41106] Fix | Delete
xrefTableData.push([1, baseOffset, gen]);
[41107] Fix | Delete
baseOffset += data.length;
[41108] Fix | Delete
} else {
[41109] Fix | Delete
gen = Math.min(ref.gen + 1, 0xffff);
[41110] Fix | Delete
xrefTableData.push([0, 0, gen]);
[41111] Fix | Delete
}
[41112] Fix | Delete
maxGen = Math.max(maxGen, gen);
[41113] Fix | Delete
}
[41114] Fix | Delete
newXref.set("Index", getIndexes(newRefs));
[41115] Fix | Delete
const offsetSize = getSizeInBytes(maxOffset);
[41116] Fix | Delete
const maxGenSize = getSizeInBytes(maxGen);
[41117] Fix | Delete
const sizes = [1, offsetSize, maxGenSize];
[41118] Fix | Delete
newXref.set("W", sizes);
[41119] Fix | Delete
computeIDs(baseOffset, xrefInfo, newXref);
[41120] Fix | Delete
const structSize = sizes.reduce((a, x) => a + x, 0);
[41121] Fix | Delete
const data = new Uint8Array(structSize * xrefTableData.length);
[41122] Fix | Delete
const stream = new Stream(data);
[41123] Fix | Delete
stream.dict = newXref;
[41124] Fix | Delete
let offset = 0;
[41125] Fix | Delete
for (const [type, objOffset, gen] of xrefTableData) {
[41126] Fix | Delete
offset = writeInt(type, sizes[0], offset, data);
[41127] Fix | Delete
offset = writeInt(objOffset, sizes[1], offset, data);
[41128] Fix | Delete
offset = writeInt(gen, sizes[2], offset, data);
[41129] Fix | Delete
}
[41130] Fix | Delete
await writeObject(xrefInfo.newRef, stream, buffer, {});
[41131] Fix | Delete
buffer.push("startxref\n", baseOffset.toString(), "\n%%EOF\n");
[41132] Fix | Delete
}
[41133] Fix | Delete
function computeIDs(baseOffset, xrefInfo, newXref) {
[41134] Fix | Delete
if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
[41135] Fix | Delete
const md5 = computeMD5(baseOffset, xrefInfo);
[41136] Fix | Delete
newXref.set("ID", [xrefInfo.fileIds[0], md5]);
[41137] Fix | Delete
}
[41138] Fix | Delete
}
[41139] Fix | Delete
function getTrailerDict(xrefInfo, newRefs, useXrefStream) {
[41140] Fix | Delete
const newXref = new Dict(null);
[41141] Fix | Delete
newXref.set("Prev", xrefInfo.startXRef);
[41142] Fix | Delete
const refForXrefTable = xrefInfo.newRef;
[41143] Fix | Delete
if (useXrefStream) {
[41144] Fix | Delete
newRefs.push({
[41145] Fix | Delete
ref: refForXrefTable,
[41146] Fix | Delete
data: ""
[41147] Fix | Delete
});
[41148] Fix | Delete
newXref.set("Size", refForXrefTable.num + 1);
[41149] Fix | Delete
newXref.set("Type", Name.get("XRef"));
[41150] Fix | Delete
} else {
[41151] Fix | Delete
newXref.set("Size", refForXrefTable.num);
[41152] Fix | Delete
}
[41153] Fix | Delete
if (xrefInfo.rootRef !== null) {
[41154] Fix | Delete
newXref.set("Root", xrefInfo.rootRef);
[41155] Fix | Delete
}
[41156] Fix | Delete
if (xrefInfo.infoRef !== null) {
[41157] Fix | Delete
newXref.set("Info", xrefInfo.infoRef);
[41158] Fix | Delete
}
[41159] Fix | Delete
if (xrefInfo.encryptRef !== null) {
[41160] Fix | Delete
newXref.set("Encrypt", xrefInfo.encryptRef);
[41161] Fix | Delete
}
[41162] Fix | Delete
return newXref;
[41163] Fix | Delete
}
[41164] Fix | Delete
async function incrementalUpdate({
[41165] Fix | Delete
originalData,
[41166] Fix | Delete
xrefInfo,
[41167] Fix | Delete
newRefs,
[41168] Fix | Delete
xref = null,
[41169] Fix | Delete
hasXfa = false,
[41170] Fix | Delete
xfaDatasetsRef = null,
[41171] Fix | Delete
hasXfaDatasetsEntry = false,
[41172] Fix | Delete
needAppearances,
[41173] Fix | Delete
acroFormRef = null,
[41174] Fix | Delete
acroForm = null,
[41175] Fix | Delete
xfaData = null,
[41176] Fix | Delete
useXrefStream = false
[41177] Fix | Delete
}) {
[41178] Fix | Delete
await updateAcroform({
[41179] Fix | Delete
xref,
[41180] Fix | Delete
acroForm,
[41181] Fix | Delete
acroFormRef,
[41182] Fix | Delete
hasXfa,
[41183] Fix | Delete
hasXfaDatasetsEntry,
[41184] Fix | Delete
xfaDatasetsRef,
[41185] Fix | Delete
needAppearances,
[41186] Fix | Delete
newRefs
[41187] Fix | Delete
});
[41188] Fix | Delete
if (hasXfa) {
[41189] Fix | Delete
updateXFA({
[41190] Fix | Delete
xfaData,
[41191] Fix | Delete
xfaDatasetsRef,
[41192] Fix | Delete
newRefs,
[41193] Fix | Delete
xref
[41194] Fix | Delete
});
[41195] Fix | Delete
}
[41196] Fix | Delete
const buffer = [];
[41197] Fix | Delete
let baseOffset = originalData.length;
[41198] Fix | Delete
const lastByte = originalData.at(-1);
[41199] Fix | Delete
if (lastByte !== 0x0a && lastByte !== 0x0d) {
[41200] Fix | Delete
buffer.push("\n");
[41201] Fix | Delete
baseOffset += 1;
[41202] Fix | Delete
}
[41203] Fix | Delete
const newXref = getTrailerDict(xrefInfo, newRefs, useXrefStream);
[41204] Fix | Delete
newRefs = newRefs.sort((a, b) => a.ref.num - b.ref.num);
[41205] Fix | Delete
for (const {
[41206] Fix | Delete
data
[41207] Fix | Delete
} of newRefs) {
[41208] Fix | Delete
if (data !== null) {
[41209] Fix | Delete
buffer.push(data);
[41210] Fix | Delete
}
[41211] Fix | Delete
}
[41212] Fix | Delete
await (useXrefStream ? getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) : getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer));
[41213] Fix | Delete
const totalLength = buffer.reduce((a, str) => a + str.length, originalData.length);
[41214] Fix | Delete
const array = new Uint8Array(totalLength);
[41215] Fix | Delete
array.set(originalData);
[41216] Fix | Delete
let offset = originalData.length;
[41217] Fix | Delete
for (const str of buffer) {
[41218] Fix | Delete
writeString(str, offset, array);
[41219] Fix | Delete
offset += str.length;
[41220] Fix | Delete
}
[41221] Fix | Delete
return array;
[41222] Fix | Delete
}
[41223] Fix | Delete
[41224] Fix | Delete
;// CONCATENATED MODULE: ./src/core/struct_tree.js
[41225] Fix | Delete
[41226] Fix | Delete
[41227] Fix | Delete
[41228] Fix | Delete
[41229] Fix | Delete
[41230] Fix | Delete
[41231] Fix | Delete
[41232] Fix | Delete
const MAX_DEPTH = 40;
[41233] Fix | Delete
const StructElementType = {
[41234] Fix | Delete
PAGE_CONTENT: 1,
[41235] Fix | Delete
STREAM_CONTENT: 2,
[41236] Fix | Delete
OBJECT: 3,
[41237] Fix | Delete
ANNOTATION: 4,
[41238] Fix | Delete
ELEMENT: 5
[41239] Fix | Delete
};
[41240] Fix | Delete
class StructTreeRoot {
[41241] Fix | Delete
constructor(rootDict, rootRef) {
[41242] Fix | Delete
this.dict = rootDict;
[41243] Fix | Delete
this.ref = rootRef instanceof Ref ? rootRef : null;
[41244] Fix | Delete
this.roleMap = new Map();
[41245] Fix | Delete
this.structParentIds = null;
[41246] Fix | Delete
}
[41247] Fix | Delete
init() {
[41248] Fix | Delete
this.readRoleMap();
[41249] Fix | Delete
}
[41250] Fix | Delete
#addIdToPage(pageRef, id, type) {
[41251] Fix | Delete
if (!(pageRef instanceof Ref) || id < 0) {
[41252] Fix | Delete
return;
[41253] Fix | Delete
}
[41254] Fix | Delete
this.structParentIds ||= new RefSetCache();
[41255] Fix | Delete
let ids = this.structParentIds.get(pageRef);
[41256] Fix | Delete
if (!ids) {
[41257] Fix | Delete
ids = [];
[41258] Fix | Delete
this.structParentIds.put(pageRef, ids);
[41259] Fix | Delete
}
[41260] Fix | Delete
ids.push([id, type]);
[41261] Fix | Delete
}
[41262] Fix | Delete
addAnnotationIdToPage(pageRef, id) {
[41263] Fix | Delete
this.#addIdToPage(pageRef, id, StructElementType.ANNOTATION);
[41264] Fix | Delete
}
[41265] Fix | Delete
readRoleMap() {
[41266] Fix | Delete
const roleMapDict = this.dict.get("RoleMap");
[41267] Fix | Delete
if (!(roleMapDict instanceof Dict)) {
[41268] Fix | Delete
return;
[41269] Fix | Delete
}
[41270] Fix | Delete
roleMapDict.forEach((key, value) => {
[41271] Fix | Delete
if (!(value instanceof Name)) {
[41272] Fix | Delete
return;
[41273] Fix | Delete
}
[41274] Fix | Delete
this.roleMap.set(key, value.name);
[41275] Fix | Delete
});
[41276] Fix | Delete
}
[41277] Fix | Delete
static async canCreateStructureTree({
[41278] Fix | Delete
catalogRef,
[41279] Fix | Delete
pdfManager,
[41280] Fix | Delete
newAnnotationsByPage
[41281] Fix | Delete
}) {
[41282] Fix | Delete
if (!(catalogRef instanceof Ref)) {
[41283] Fix | Delete
warn("Cannot save the struct tree: no catalog reference.");
[41284] Fix | Delete
return false;
[41285] Fix | Delete
}
[41286] Fix | Delete
let nextKey = 0;
[41287] Fix | Delete
let hasNothingToUpdate = true;
[41288] Fix | Delete
for (const [pageIndex, elements] of newAnnotationsByPage) {
[41289] Fix | Delete
const {
[41290] Fix | Delete
ref: pageRef
[41291] Fix | Delete
} = await pdfManager.getPage(pageIndex);
[41292] Fix | Delete
if (!(pageRef instanceof Ref)) {
[41293] Fix | Delete
warn(`Cannot save the struct tree: page ${pageIndex} has no ref.`);
[41294] Fix | Delete
hasNothingToUpdate = true;
[41295] Fix | Delete
break;
[41296] Fix | Delete
}
[41297] Fix | Delete
for (const element of elements) {
[41298] Fix | Delete
if (element.accessibilityData?.type) {
[41299] Fix | Delete
element.parentTreeId = nextKey++;
[41300] Fix | Delete
hasNothingToUpdate = false;
[41301] Fix | Delete
}
[41302] Fix | Delete
}
[41303] Fix | Delete
}
[41304] Fix | Delete
if (hasNothingToUpdate) {
[41305] Fix | Delete
for (const elements of newAnnotationsByPage.values()) {
[41306] Fix | Delete
for (const element of elements) {
[41307] Fix | Delete
delete element.parentTreeId;
[41308] Fix | Delete
}
[41309] Fix | Delete
}
[41310] Fix | Delete
return false;
[41311] Fix | Delete
}
[41312] Fix | Delete
return true;
[41313] Fix | Delete
}
[41314] Fix | Delete
static async createStructureTree({
[41315] Fix | Delete
newAnnotationsByPage,
[41316] Fix | Delete
xref,
[41317] Fix | Delete
catalogRef,
[41318] Fix | Delete
pdfManager,
[41319] Fix | Delete
newRefs
[41320] Fix | Delete
}) {
[41321] Fix | Delete
const root = pdfManager.catalog.cloneDict();
[41322] Fix | Delete
const cache = new RefSetCache();
[41323] Fix | Delete
cache.put(catalogRef, root);
[41324] Fix | Delete
const structTreeRootRef = xref.getNewTemporaryRef();
[41325] Fix | Delete
root.set("StructTreeRoot", structTreeRootRef);
[41326] Fix | Delete
const structTreeRoot = new Dict(xref);
[41327] Fix | Delete
structTreeRoot.set("Type", Name.get("StructTreeRoot"));
[41328] Fix | Delete
const parentTreeRef = xref.getNewTemporaryRef();
[41329] Fix | Delete
structTreeRoot.set("ParentTree", parentTreeRef);
[41330] Fix | Delete
const kids = [];
[41331] Fix | Delete
structTreeRoot.set("K", kids);
[41332] Fix | Delete
cache.put(structTreeRootRef, structTreeRoot);
[41333] Fix | Delete
const parentTree = new Dict(xref);
[41334] Fix | Delete
const nums = [];
[41335] Fix | Delete
parentTree.set("Nums", nums);
[41336] Fix | Delete
const nextKey = await this.#writeKids({
[41337] Fix | Delete
newAnnotationsByPage,
[41338] Fix | Delete
structTreeRootRef,
[41339] Fix | Delete
kids,
[41340] Fix | Delete
nums,
[41341] Fix | Delete
xref,
[41342] Fix | Delete
pdfManager,
[41343] Fix | Delete
cache
[41344] Fix | Delete
});
[41345] Fix | Delete
structTreeRoot.set("ParentTreeNextKey", nextKey);
[41346] Fix | Delete
cache.put(parentTreeRef, parentTree);
[41347] Fix | Delete
const buffer = [];
[41348] Fix | Delete
for (const [ref, obj] of cache.items()) {
[41349] Fix | Delete
buffer.length = 0;
[41350] Fix | Delete
await writeObject(ref, obj, buffer, xref);
[41351] Fix | Delete
newRefs.push({
[41352] Fix | Delete
ref,
[41353] Fix | Delete
data: buffer.join("")
[41354] Fix | Delete
});
[41355] Fix | Delete
}
[41356] Fix | Delete
}
[41357] Fix | Delete
async canUpdateStructTree({
[41358] Fix | Delete
pdfManager,
[41359] Fix | Delete
xref,
[41360] Fix | Delete
newAnnotationsByPage
[41361] Fix | Delete
}) {
[41362] Fix | Delete
if (!this.ref) {
[41363] Fix | Delete
warn("Cannot update the struct tree: no root reference.");
[41364] Fix | Delete
return false;
[41365] Fix | Delete
}
[41366] Fix | Delete
let nextKey = this.dict.get("ParentTreeNextKey");
[41367] Fix | Delete
if (!Number.isInteger(nextKey) || nextKey < 0) {
[41368] Fix | Delete
warn("Cannot update the struct tree: invalid next key.");
[41369] Fix | Delete
return false;
[41370] Fix | Delete
}
[41371] Fix | Delete
const parentTree = this.dict.get("ParentTree");
[41372] Fix | Delete
if (!(parentTree instanceof Dict)) {
[41373] Fix | Delete
warn("Cannot update the struct tree: ParentTree isn't a dict.");
[41374] Fix | Delete
return false;
[41375] Fix | Delete
}
[41376] Fix | Delete
const nums = parentTree.get("Nums");
[41377] Fix | Delete
if (!Array.isArray(nums)) {
[41378] Fix | Delete
warn("Cannot update the struct tree: nums isn't an array.");
[41379] Fix | Delete
return false;
[41380] Fix | Delete
}
[41381] Fix | Delete
const numberTree = new NumberTree(parentTree, xref);
[41382] Fix | Delete
for (const pageIndex of newAnnotationsByPage.keys()) {
[41383] Fix | Delete
const {
[41384] Fix | Delete
pageDict
[41385] Fix | Delete
} = await pdfManager.getPage(pageIndex);
[41386] Fix | Delete
if (!pageDict.has("StructParents")) {
[41387] Fix | Delete
continue;
[41388] Fix | Delete
}
[41389] Fix | Delete
const id = pageDict.get("StructParents");
[41390] Fix | Delete
if (!Number.isInteger(id) || !Array.isArray(numberTree.get(id))) {
[41391] Fix | Delete
warn(`Cannot save the struct tree: page ${pageIndex} has a wrong id.`);
[41392] Fix | Delete
return false;
[41393] Fix | Delete
}
[41394] Fix | Delete
}
[41395] Fix | Delete
let hasNothingToUpdate = true;
[41396] Fix | Delete
for (const [pageIndex, elements] of newAnnotationsByPage) {
[41397] Fix | Delete
const {
[41398] Fix | Delete
pageDict
[41399] Fix | Delete
} = await pdfManager.getPage(pageIndex);
[41400] Fix | Delete
StructTreeRoot.#collectParents({
[41401] Fix | Delete
elements,
[41402] Fix | Delete
xref: this.dict.xref,
[41403] Fix | Delete
pageDict,
[41404] Fix | Delete
numberTree
[41405] Fix | Delete
});
[41406] Fix | Delete
for (const element of elements) {
[41407] Fix | Delete
if (element.accessibilityData?.type) {
[41408] Fix | Delete
element.parentTreeId = nextKey++;
[41409] Fix | Delete
hasNothingToUpdate = false;
[41410] Fix | Delete
}
[41411] Fix | Delete
}
[41412] Fix | Delete
}
[41413] Fix | Delete
if (hasNothingToUpdate) {
[41414] Fix | Delete
for (const elements of newAnnotationsByPage.values()) {
[41415] Fix | Delete
for (const element of elements) {
[41416] Fix | Delete
delete element.parentTreeId;
[41417] Fix | Delete
delete element.structTreeParent;
[41418] Fix | Delete
}
[41419] Fix | Delete
}
[41420] Fix | Delete
return false;
[41421] Fix | Delete
}
[41422] Fix | Delete
return true;
[41423] Fix | Delete
}
[41424] Fix | Delete
async updateStructureTree({
[41425] Fix | Delete
newAnnotationsByPage,
[41426] Fix | Delete
pdfManager,
[41427] Fix | Delete
newRefs
[41428] Fix | Delete
}) {
[41429] Fix | Delete
const xref = this.dict.xref;
[41430] Fix | Delete
const structTreeRoot = this.dict.clone();
[41431] Fix | Delete
const structTreeRootRef = this.ref;
[41432] Fix | Delete
const cache = new RefSetCache();
[41433] Fix | Delete
cache.put(structTreeRootRef, structTreeRoot);
[41434] Fix | Delete
let parentTreeRef = structTreeRoot.getRaw("ParentTree");
[41435] Fix | Delete
let parentTree;
[41436] Fix | Delete
if (parentTreeRef instanceof Ref) {
[41437] Fix | Delete
parentTree = xref.fetch(parentTreeRef);
[41438] Fix | Delete
} else {
[41439] Fix | Delete
parentTree = parentTreeRef;
[41440] Fix | Delete
parentTreeRef = xref.getNewTemporaryRef();
[41441] Fix | Delete
structTreeRoot.set("ParentTree", parentTreeRef);
[41442] Fix | Delete
}
[41443] Fix | Delete
parentTree = parentTree.clone();
[41444] Fix | Delete
cache.put(parentTreeRef, parentTree);
[41445] Fix | Delete
let nums = parentTree.getRaw("Nums");
[41446] Fix | Delete
let numsRef = null;
[41447] Fix | Delete
if (nums instanceof Ref) {
[41448] Fix | Delete
numsRef = nums;
[41449] Fix | Delete
nums = xref.fetch(numsRef);
[41450] Fix | Delete
}
[41451] Fix | Delete
nums = nums.slice();
[41452] Fix | Delete
if (!numsRef) {
[41453] Fix | Delete
parentTree.set("Nums", nums);
[41454] Fix | Delete
}
[41455] Fix | Delete
const newNextkey = await StructTreeRoot.#writeKids({
[41456] Fix | Delete
newAnnotationsByPage,
[41457] Fix | Delete
structTreeRootRef,
[41458] Fix | Delete
kids: null,
[41459] Fix | Delete
nums,
[41460] Fix | Delete
xref,
[41461] Fix | Delete
pdfManager,
[41462] Fix | Delete
cache
[41463] Fix | Delete
});
[41464] Fix | Delete
structTreeRoot.set("ParentTreeNextKey", newNextkey);
[41465] Fix | Delete
if (numsRef) {
[41466] Fix | Delete
cache.put(numsRef, nums);
[41467] Fix | Delete
}
[41468] Fix | Delete
const buffer = [];
[41469] Fix | Delete
for (const [ref, obj] of cache.items()) {
[41470] Fix | Delete
buffer.length = 0;
[41471] Fix | Delete
await writeObject(ref, obj, buffer, xref);
[41472] Fix | Delete
newRefs.push({
[41473] Fix | Delete
ref,
[41474] Fix | Delete
data: buffer.join("")
[41475] Fix | Delete
});
[41476] Fix | Delete
}
[41477] Fix | Delete
}
[41478] Fix | Delete
static async #writeKids({
[41479] Fix | Delete
newAnnotationsByPage,
[41480] Fix | Delete
structTreeRootRef,
[41481] Fix | Delete
kids,
[41482] Fix | Delete
nums,
[41483] Fix | Delete
xref,
[41484] Fix | Delete
pdfManager,
[41485] Fix | Delete
cache
[41486] Fix | Delete
}) {
[41487] Fix | Delete
const objr = Name.get("OBJR");
[41488] Fix | Delete
let nextKey = -Infinity;
[41489] Fix | Delete
for (const [pageIndex, elements] of newAnnotationsByPage) {
[41490] Fix | Delete
const {
[41491] Fix | Delete
ref: pageRef
[41492] Fix | Delete
} = await pdfManager.getPage(pageIndex);
[41493] Fix | Delete
const isPageRef = pageRef instanceof Ref;
[41494] Fix | Delete
for (const {
[41495] Fix | Delete
accessibilityData,
[41496] Fix | Delete
ref,
[41497] Fix | Delete
parentTreeId,
[41498] Fix | Delete
structTreeParent
[41499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function