{"record":{"id":"e849ec9b0c8572b4","repo":"mozilla/pdf.js","slug":"no-textcontentsource-parameter-specified","errorCode":null,"errorMessage":"No \"textContentSource\" parameter specified.","messagePattern":"No \"textContentSource\" parameter specified\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/text_layer.js","lineNumber":119,"sourceCode":"\n  /**\n   * @param {TextLayerParameters} options\n   */\n  constructor({ textContentSource, images, container, viewport }) {\n    if (textContentSource instanceof ReadableStream) {\n      this.#textContentSource = textContentSource;\n    } else if (\n      (typeof PDFJSDev === \"undefined\" || PDFJSDev.test(\"GENERIC\")) &&\n      typeof textContentSource === \"object\"\n    ) {\n      this.#textContentSource = new ReadableStream({\n        start(controller) {\n          controller.enqueue(textContentSource);\n          controller.close();\n        },\n      });\n    } else {\n      throw new Error('No \"textContentSource\" parameter specified.');\n    }\n    this.#container = this.#rootContainer = container;\n\n    this.#imagesHandler = images;\n\n    this.#scale = viewport.scale * OutputScale.pixelRatio;\n    this.#rotation = viewport.rotation;\n    this.#layoutTextParams = {\n      div: null,\n      properties: null,\n      ctx: null,\n    };\n    const { pageWidth, pageHeight, pageX, pageY } = viewport.rawDims;\n    this.#transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];\n    this.#pageWidth = pageWidth;\n    this.#pageHeight = pageHeight;\n\n    TextLayer.#ensureMinFontSizeComputed();","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/text_layer.js#L101-L137","documentation":"Thrown by the TextLayer constructor when textContentSource is neither a ReadableStream nor, in the GENERIC build, a plain object. The text layer needs a stream of text-content items to lay out, so a missing or wrong-typed source is a hard configuration error. The GENERIC build additionally accepts a raw object by wrapping it in a one-shot stream.","triggerScenarios":"new TextLayer({ textContentSource: undefined, container, viewport }) or passing a number/string/Promise instead of a stream/object.","commonSituations":"Forgetting to pass textContentSource; passing the awaited text content array in a non-GENERIC build; passing null after a failed page.streamTextContent().","solutions":["Pass the ReadableStream from await page.streamTextContent() as textContentSource.","In GENERIC builds you may pass the text-content object directly; otherwise wrap it.","Ensure the value is not null/undefined before constructing the layer.","Check that the build target (GENERIC vs others) matches how you supply content."],"exampleFix":"// before\nconst textLayer = new TextLayer({ textContentSource: undefined, container, viewport });\n// after\nconst stream = await page.streamTextContent();\nconst textLayer = new TextLayer({ textContentSource: stream, container, viewport });","handlingStrategy":"validation","validationCode":"const source = await page.streamTextContent();\nif (!(source instanceof ReadableStream)) {\n  throw new Error('textContentSource must be a ReadableStream');\n}\nconst textLayer = new TextLayer({ textContentSource: source, container, viewport });","typeGuard":"function isValidTextContentSource(src) {\n  return src instanceof ReadableStream || (typeof src === 'object' && src !== null && !(src instanceof Promise));\n}","tryCatchPattern":null,"preventionTips":["Always pass the stream from page.streamTextContent() as textContentSource.","Never pass null/undefined/Promise as the source.","In non-GENERIC builds, do not pass a raw object; pass a stream.","Confirm your build target matches how you supply text content."],"tags":["text-layer","constructor","input-validation","stream"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}