: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
sink.enqueue(textContent, length);
textContent.styles = Object.create(null);
const timeSlotManager = new TimeSlotManager();
return new Promise(function promiseBody(resolve, reject) {
const next = function (promise) {
Promise.all([promise, sink.ready]).then(function () {
promiseBody(resolve, reject);
task.ensureNotTerminated();
while (!(stop = timeSlotManager.check())) {
if (!preprocessor.read(operation)) {
const previousState = textState;
textState = stateManager.state;
var fontNameArg = args[0].name,
if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
textState.fontName = fontNameArg;
textState.fontSize = fontSizeArg;
next(handleSetFont(fontNameArg, null));
textState.textRise = args[0];
textState.textHScale = args[0] / 100;
textState.leading = args[0];
textState.translateTextLineMatrix(args[0], args[1]);
textState.textMatrix = textState.textLineMatrix.slice();
case OPS.setLeadingMoveText:
textState.leading = -args[1];
textState.translateTextLineMatrix(args[0], args[1]);
textState.textMatrix = textState.textLineMatrix.slice();
textState.carriageReturn();
textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
textState.charSpacing = args[0];
textState.wordSpacing = args[0];
textState.textMatrix = IDENTITY_MATRIX.slice();
textState.textLineMatrix = IDENTITY_MATRIX.slice();
if (!stateManager.state.font) {
self.ensureStateFont(stateManager.state);
const spaceFactor = (textState.font.vertical ? 1 : -1) * textState.fontSize / 1000;
const elements = args[0];
for (let i = 0, ii = elements.length; i < ii; i++) {
const item = elements[i];
if (typeof item === "string") {
showSpacedTextBuffer.push(item);
} else if (typeof item === "number" && item !== 0) {
const str = showSpacedTextBuffer.join("");
showSpacedTextBuffer.length = 0;
extraSpacing: item * spaceFactor
if (showSpacedTextBuffer.length > 0) {
const str = showSpacedTextBuffer.join("");
showSpacedTextBuffer.length = 0;
if (!stateManager.state.font) {
self.ensureStateFont(stateManager.state);
case OPS.nextLineShowText:
if (!stateManager.state.font) {
self.ensureStateFont(stateManager.state);
textState.carriageReturn();
case OPS.nextLineSetSpacingShowText:
if (!stateManager.state.font) {
self.ensureStateFont(stateManager.state);
textState.wordSpacing = args[0];
textState.charSpacing = args[1];
textState.carriageReturn();
xobjs = resources.get("XObject") || Dict.empty;
var isValidName = args[0] instanceof Name;
if (isValidName && emptyXObjectCache.getByName(name)) {
next(new Promise(function (resolveXObject, rejectXObject) {
throw new FormatError("XObject must be referred to by name.");
let xobj = xobjs.getRaw(name);
if (xobj instanceof Ref) {
if (emptyXObjectCache.getByRef(xobj)) {
const globalImage = self.globalImageCache.getData(xobj, self.pageIndex);
if (!(xobj instanceof BaseStream)) {
throw new FormatError("XObject should be a stream");
const type = xobj.dict.get("Subtype");
if (!(type instanceof Name)) {
throw new FormatError("XObject should have a Name subtype");
if (type.name !== "Form") {
emptyXObjectCache.set(name, xobj.dict.objId, true);
const currentState = stateManager.state.clone();
const xObjStateManager = new StateManager(currentState);
const matrix = lookupMatrix(xobj.dict.getArray("Matrix"), null);
xObjStateManager.transform(matrix);
this.enqueueInvoked = true;
sink.enqueue(chunk, size);
resources: xobj.dict.get("Resources") || resources,
stateManager: xObjStateManager,
if (!sinkWrapper.enqueueInvoked) {
emptyXObjectCache.set(name, xobj.dict.objId, true);
}).catch(function (reason) {
if (reason instanceof AbortException) {
if (self.options.ignoreErrors) {
warn(`getTextContent - ignoring XObject: "${reason}".`);
isValidName = args[0] instanceof Name;
if (isValidName && emptyGStateCache.getByName(name)) {
next(new Promise(function (resolveGState, rejectGState) {
throw new FormatError("GState must be referred to by name.");
const extGState = resources.get("ExtGState");
if (!(extGState instanceof Dict)) {
throw new FormatError("ExtGState should be a dictionary.");
const gState = extGState.get(name);
if (!(gState instanceof Dict)) {
throw new FormatError("GState should be a dictionary.");
const gStateFont = gState.get("Font");
emptyGStateCache.set(name, gState.objId, true);
textState.fontName = null;
textState.fontSize = gStateFont[1];
handleSetFont(null, gStateFont[0]).then(resolveGState, rejectGState);
}).catch(function (reason) {
if (reason instanceof AbortException) {
if (self.options.ignoreErrors) {
warn(`getTextContent - ignoring ExtGState: "${reason}".`);
case OPS.beginMarkedContent:
if (includeMarkedContent) {
markedContentData.level++;
type: "beginMarkedContent",
tag: args[0] instanceof Name ? args[0].name : null
case OPS.beginMarkedContentProps:
if (includeMarkedContent) {
markedContentData.level++;
if (args[1] instanceof Dict) {
mcid = args[1].get("MCID");
type: "beginMarkedContentProps",
id: Number.isInteger(mcid) ? `${self.idFactory.getPageObjId()}_mc${mcid}` : null,
tag: args[0] instanceof Name ? args[0].name : null
case OPS.endMarkedContent:
if (includeMarkedContent) {
if (markedContentData.level === 0) {
markedContentData.level--;
if (previousState && (previousState.font !== textState.font || previousState.fontSize !== textState.fontSize || previousState.fontName !== textState.fontName)) {
if (textContent.items.length >= sink.desiredSize) {
if (reason instanceof AbortException) {
if (this.options.ignoreErrors) {
warn(`getTextContent - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
async extractDataStructures(dict, properties) {
const toUnicodePromise = this.readToUnicode(properties.toUnicode);
if (properties.composite) {
const cidSystemInfo = dict.get("CIDSystemInfo");
if (cidSystemInfo instanceof Dict) {
properties.cidSystemInfo = {
registry: stringToPDFString(cidSystemInfo.get("Registry")),
ordering: stringToPDFString(cidSystemInfo.get("Ordering")),
supplement: cidSystemInfo.get("Supplement")
const cidToGidMap = dict.get("CIDToGIDMap");
if (cidToGidMap instanceof BaseStream) {
cidToGidBytes = cidToGidMap.getBytes();
if (!this.options.ignoreErrors) {
warn(`extractDataStructures - ignoring CIDToGIDMap data: "${ex}".`);
let baseEncodingName = null;
if (dict.has("Encoding")) {
encoding = dict.get("Encoding");
if (encoding instanceof Dict) {
baseEncodingName = encoding.get("BaseEncoding");
baseEncodingName = baseEncodingName instanceof Name ? baseEncodingName.name : null;
if (encoding.has("Differences")) {
const diffEncoding = encoding.get("Differences");
for (const entry of diffEncoding) {
const data = xref.fetchIfRef(entry);
if (typeof data === "number") {
} else if (data instanceof Name) {
differences[index++] = data.name;
throw new FormatError(`Invalid entry in 'Differences' array: ${data}`);
} else if (encoding instanceof Name) {
baseEncodingName = encoding.name;
const msg = "Encoding is not a Name nor a Dict";
if (!this.options.ignoreErrors) {
throw new FormatError(msg);
if (baseEncodingName !== "MacRomanEncoding" && baseEncodingName !== "MacExpertEncoding" && baseEncodingName !== "WinAnsiEncoding") {
const nonEmbeddedFont = !properties.file || properties.isInternalFont,
isSymbolsFontName = getSymbolsFonts()[properties.name];
if (baseEncodingName && nonEmbeddedFont && isSymbolsFontName) {
properties.defaultEncoding = getEncoding(baseEncodingName);
const isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
const isNonsymbolicFont = !!(properties.flags & FontFlags.Nonsymbolic);
encoding = StandardEncoding;
if (properties.type === "TrueType" && !isNonsymbolicFont) {
encoding = WinAnsiEncoding;
if (isSymbolicFont || isSymbolsFontName) {
encoding = MacRomanEncoding;
if (/Symbol/i.test(properties.name)) {
encoding = SymbolSetEncoding;
} else if (/Dingbats/i.test(properties.name)) {
encoding = ZapfDingbatsEncoding;
} else if (/Wingdings/i.test(properties.name)) {
encoding = WinAnsiEncoding;
properties.defaultEncoding = encoding;
properties.differences = differences;
properties.baseEncodingName = baseEncodingName;
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
properties.toUnicode = await toUnicodePromise;
const builtToUnicode = await this.buildToUnicode(properties);
properties.toUnicode = builtToUnicode;
properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode);
_simpleFontToUnicode(properties, forceGlyphs = false) {
assert(!properties.composite, "Must be a simple font.");
const encoding = properties.defaultEncoding.slice();
const baseEncodingName = properties.baseEncodingName;
const differences = properties.differences;
for (const charcode in differences) {
const glyphName = differences[charcode];
if (glyphName === ".notdef") {
encoding[charcode] = glyphName;
const glyphsUnicodeMap = getGlyphsUnicode();
for (const charcode in encoding) {
let glyphName = encoding[charcode];
let unicode = glyphsUnicodeMap[glyphName];
if (unicode !== undefined) {
toUnicode[charcode] = String.fromCharCode(unicode);
if (glyphName.length === 3) {
code = parseInt(glyphName.substring(1), 16);
if (glyphName.length === 5) {
code = parseInt(glyphName.substring(1), 16);
if (glyphName.length >= 3 && glyphName.length <= 4) {
const codeStr = glyphName.substring(1);
code = parseInt(codeStr, 16);
if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) {
return this._simpleFontToUnicode(properties, true);
unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
toUnicode[charcode] = glyphName.replaceAll("_", "");