: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
throw new Error(`Page index ${pageIndex} not found.`);
async getAllPageDicts(recoveryMode = false) {
} = this.pdfManager.evaluatorOptions;
currentNode: this.toplevelPagesDict,
const visitedNodes = new RefSet();
const pagesRef = this._catDict.getRaw("Pages");
if (pagesRef instanceof Ref) {
visitedNodes.put(pagesRef);
pageIndexCache = this.pageIndexCache;
function addPageDict(pageDict, pageRef) {
if (pageRef && !pageIndexCache.has(pageRef)) {
pageIndexCache.put(pageRef, pageIndex);
map.set(pageIndex++, [pageDict, pageRef]);
function addPageError(error) {
if (error instanceof XRefEntryException && !recoveryMode) {
if (recoveryMode && ignoreErrors && pageIndex === 0) {
warn(`getAllPageDicts - Skipping invalid first page: "${error}".`);
map.set(pageIndex++, [error, null]);
while (queue.length > 0) {
const queueItem = queue.at(-1);
let kids = currentNode.getRaw("Kids");
if (kids instanceof Ref) {
kids = await xref.fetchAsync(kids);
if (!Array.isArray(kids)) {
addPageError(new FormatError("Page dictionary kids object is not an array."));
if (posInKids >= kids.length) {
const kidObj = kids[posInKids];
if (kidObj instanceof Ref) {
if (visitedNodes.has(kidObj)) {
addPageError(new FormatError("Pages tree contains circular reference."));
visitedNodes.put(kidObj);
obj = await xref.fetchAsync(kidObj);
if (!(obj instanceof Dict)) {
addPageError(new FormatError("Page dictionary kid reference points to wrong type of object."));
let type = obj.getRaw("Type");
if (type instanceof Ref) {
type = await xref.fetchAsync(type);
if (isName(type, "Page") || !obj.has("Kids")) {
addPageDict(obj, kidObj instanceof Ref ? kidObj : null);
const cachedPageIndex = this.pageIndexCache.get(pageRef);
if (cachedPageIndex !== undefined) {
return Promise.resolve(cachedPageIndex);
function pagesBeforeRef(kidRef) {
return xref.fetchAsync(kidRef).then(function (node) {
if (isRefsEqual(kidRef, pageRef) && !isDict(node, "Page") && !(node instanceof Dict && !node.has("Type") && node.has("Contents"))) {
throw new FormatError("The reference does not point to a /Page dictionary.");
if (!(node instanceof Dict)) {
throw new FormatError("Node must be a dictionary.");
parentRef = node.getRaw("Parent");
return node.getAsync("Parent");
}).then(function (parent) {
if (!(parent instanceof Dict)) {
throw new FormatError("Parent must be a dictionary.");
return parent.getAsync("Kids");
}).then(function (kids) {
for (const kid of kids) {
if (!(kid instanceof Ref)) {
throw new FormatError("Kid must be a reference.");
if (isRefsEqual(kid, kidRef)) {
kidPromises.push(xref.fetchAsync(kid).then(function (obj) {
if (!(obj instanceof Dict)) {
throw new FormatError("Kid node must be a dictionary.");
total += obj.get("Count");
throw new FormatError("Kid reference not found in parent's kids.");
return Promise.all(kidPromises).then(function () {
return [total, parentRef];
const next = ref => pagesBeforeRef(ref).then(args => {
this.pageIndexCache.put(pageRef, total);
const [count, parentRef] = args;
const uri = this._catDict.get("URI");
if (uri instanceof Dict) {
const base = uri.get("Base");
if (typeof base === "string") {
const absoluteUrl = createValidAbsoluteUrl(base, null, {
return shadow(this, "baseUrl", absoluteUrl.href);
return shadow(this, "baseUrl", this.pdfManager.docBaseUrl);
static parseDestDictionary({
if (!(destDict instanceof Dict)) {
warn("parseDestDictionary: `destDict` must be a dictionary.");
let action = destDict.get("A"),
if (!(action instanceof Dict)) {
if (destDict.has("Dest")) {
action = destDict.get("Dest");
action = destDict.get("AA");
if (action instanceof Dict) {
action = action.get("D");
} else if (action.has("U")) {
action = action.get("U");
if (action instanceof Dict) {
const actionType = action.get("S");
if (!(actionType instanceof Name)) {
warn("parseDestDictionary: Invalid type in Action dictionary.");
const actionName = actionType.name;
const flags = action.get("Flags");
const include = ((typeof flags === "number" ? flags : 0) & 1) === 0;
for (const obj of action.get("Fields") || []) {
if (obj instanceof Ref) {
refs.push(obj.toString());
} else if (typeof obj === "string") {
fields.push(stringToPDFString(obj));
if (url instanceof Name) {
const urlDict = action.get("F");
if (urlDict instanceof Dict) {
const fs = new FileSpec(urlDict, null, true);
} else if (typeof urlDict === "string") {
const remoteDest = fetchRemoteDest(action);
if (remoteDest && typeof url === "string") {
url = url.split("#", 1)[0] + "#" + remoteDest;
const newWindow = action.get("NewWindow");
if (typeof newWindow === "boolean") {
resultObj.newWindow = newWindow;
const target = action.get("T");
if (docAttachments && target instanceof Dict) {
const relationship = target.get("R");
const name = target.get("N");
if (isName(relationship, "C") && typeof name === "string") {
attachment = docAttachments[stringToPDFString(name)];
resultObj.attachment = attachment;
const attachmentDest = fetchRemoteDest(action);
resultObj.attachmentDest = attachmentDest;
warn(`parseDestDictionary - unimplemented "GoToE" action.`);
const namedAction = action.get("N");
if (namedAction instanceof Name) {
resultObj.action = namedAction.name;
const state = action.get("State");
const preserveRB = action.get("PreserveRB");
if (!Array.isArray(state) || state.length === 0) {
for (const elem of state) {
if (elem instanceof Name) {
stateArr.push(elem.name);
} else if (elem instanceof Ref) {
stateArr.push(elem.toString());
if (stateArr.length !== state.length) {
resultObj.setOCGState = {
preserveRB: typeof preserveRB === "boolean" ? preserveRB : true
const jsAction = action.get("JS");
if (jsAction instanceof BaseStream) {
js = jsAction.getString();
} else if (typeof jsAction === "string") {
const jsURL = js && recoverJsURL(stringToPDFString(js));
resultObj.newWindow = jsURL.newWindow;
if (actionName === "JavaScript" || actionName === "SubmitForm") {
warn(`parseDestDictionary - unsupported action: "${actionName}".`);
} else if (destDict.has("Dest")) {
dest = destDict.get("Dest");
if (typeof url === "string") {
const absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl, {
addDefaultProtocol: true,
resultObj.url = absoluteUrl.href;
resultObj.unsafeUrl = url;
if (dest instanceof Name) {
if (typeof dest === "string") {
resultObj.dest = stringToPDFString(dest);
} else if (isValidExplicitDest(dest)) {
;// CONCATENATED MODULE: ./src/core/object_loader.js
function mayHaveChildren(value) {
return value instanceof Ref || value instanceof Dict || value instanceof BaseStream || Array.isArray(value);
function addChildren(node, nodesToVisit) {
if (node instanceof Dict) {
node = node.getRawValues();
} else if (node instanceof BaseStream) {
node = node.dict.getRawValues();
} else if (!Array.isArray(node)) {
for (const rawValue of node) {
if (mayHaveChildren(rawValue)) {
nodesToVisit.push(rawValue);
constructor(dict, keys, xref) {
if (this.xref.stream.isDataLoaded) {
this.refSet = new RefSet();
for (const key of keys) {
const rawValue = dict.getRaw(key);
if (rawValue !== undefined) {
nodesToVisit.push(rawValue);
return this._walk(nodesToVisit);
async _walk(nodesToVisit) {
const nodesToRevisit = [];
const pendingRequests = [];
while (nodesToVisit.length) {
let currentNode = nodesToVisit.pop();
if (currentNode instanceof Ref) {
if (this.refSet.has(currentNode)) {
this.refSet.put(currentNode);
currentNode = this.xref.fetch(currentNode);
if (!(ex instanceof MissingDataException)) {
warn(`ObjectLoader._walk - requesting all data: "${ex}".`);
return manager.requestAllChunks();
nodesToRevisit.push(currentNode);
if (currentNode instanceof BaseStream) {
const baseStreams = currentNode.getBaseStreams();
let foundMissingData = false;
for (const stream of baseStreams) {
if (stream.isDataLoaded) {
nodesToRevisit.push(currentNode);
addChildren(currentNode, nodesToVisit);
if (pendingRequests.length) {
await this.xref.stream.manager.requestRanges(pendingRequests);
for (const node of nodesToRevisit) {
if (node instanceof Ref) {
this.refSet.remove(node);
return this._walk(nodesToRevisit);
;// CONCATENATED MODULE: ./src/core/xfa/symbol_utils.js
const $acceptWhitespace = Symbol();
const $addHTML = Symbol();
const $appendChild = Symbol();
const $childrenToHTML = Symbol();
const $cleanPage = Symbol();
const $cleanup = Symbol();
const $consumed = Symbol();
const $content = Symbol("content");
const $data = Symbol("data");
const $extra = Symbol("extra");
const $finalize = Symbol();
const $flushHTML = Symbol();