: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (typeof src !== "object") {
throw new Error("Invalid parameter in getDocument, need parameter object.");
if (!src.url && !src.data && !src.range) {
throw new Error("Invalid parameter object: need either .data, .range or .url");
const task = new PDFDocumentLoadingTask();
const url = src.url ? getUrlProp(src.url) : null;
const data = src.data ? getDataProp(src.data) : null;
const httpHeaders = src.httpHeaders || null;
const withCredentials = src.withCredentials === true;
const password = src.password ?? null;
const rangeTransport = src.range instanceof PDFDataRangeTransport ? src.range : null;
const rangeChunkSize = Number.isInteger(src.rangeChunkSize) && src.rangeChunkSize > 0 ? src.rangeChunkSize : DEFAULT_RANGE_CHUNK_SIZE;
let worker = src.worker instanceof PDFWorker ? src.worker : null;
const verbosity = src.verbosity;
const docBaseUrl = typeof src.docBaseUrl === "string" && !isDataScheme(src.docBaseUrl) ? src.docBaseUrl : null;
const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
const cMapPacked = src.cMapPacked !== false;
const CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
const standardFontDataUrl = typeof src.standardFontDataUrl === "string" ? src.standardFontDataUrl : null;
const StandardFontDataFactory = src.StandardFontDataFactory || DefaultStandardFontDataFactory;
const ignoreErrors = src.stopAtErrors !== true;
const maxImageSize = Number.isInteger(src.maxImageSize) && src.maxImageSize > -1 ? src.maxImageSize : -1;
const isEvalSupported = src.isEvalSupported !== false;
const isOffscreenCanvasSupported = typeof src.isOffscreenCanvasSupported === "boolean" ? src.isOffscreenCanvasSupported : !isNodeJS;
const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1;
const disableFontFace = typeof src.disableFontFace === "boolean" ? src.disableFontFace : isNodeJS;
const fontExtraProperties = src.fontExtraProperties === true;
const enableXfa = src.enableXfa === true;
const ownerDocument = src.ownerDocument || globalThis.document;
const disableRange = src.disableRange === true;
const disableStream = src.disableStream === true;
const disableAutoFetch = src.disableAutoFetch === true;
const pdfBug = src.pdfBug === true;
const length = rangeTransport ? rangeTransport.length : src.length ?? NaN;
const useSystemFonts = typeof src.useSystemFonts === "boolean" ? src.useSystemFonts : !isNodeJS && !disableFontFace;
const useWorkerFetch = typeof src.useWorkerFetch === "boolean" ? src.useWorkerFetch : CMapReaderFactory === DOMCMapReaderFactory && StandardFontDataFactory === DOMStandardFontDataFactory && cMapUrl && standardFontDataUrl && isValidFetchUrl(cMapUrl, document.baseURI) && isValidFetchUrl(standardFontDataUrl, document.baseURI);
const canvasFactory = src.canvasFactory || new DefaultCanvasFactory({
const filterFactory = src.filterFactory || new DefaultFilterFactory({
const styleElement = null;
setVerbosityLevel(verbosity);
const transportFactory = {
transportFactory.cMapReaderFactory = new CMapReaderFactory({
transportFactory.standardFontDataFactory = new StandardFontDataFactory({
baseUrl: standardFontDataUrl
port: GlobalWorkerOptions.workerPort
worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
isOffscreenCanvasSupported,
cMapUrl: useWorkerFetch ? cMapUrl : null,
standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
const transportParams = {
worker.promise.then(function () {
throw new Error("Loading aborted");
throw new Error("Worker was destroyed");
const workerIdPromise = worker.messageHandler.sendWithPromise("GetDocRequest", docParams, data ? [data.buffer] : null);
networkStream = new PDFDataTransportStream(rangeTransport, {
const createPDFNetworkStream = params => {
const isFetchSupported = function () {
return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype;
return isFetchSupported() && isValidFetchUrl(params.url) ? new PDFFetchStream(params) : new PDFNodeStream(params);
return isValidFetchUrl(params.url) ? new PDFFetchStream(params) : new PDFNetworkStream(params);
networkStream = createPDFNetworkStream({
return workerIdPromise.then(workerId => {
throw new Error("Loading aborted");
throw new Error("Worker was destroyed");
const messageHandler = new MessageHandler(docId, workerId, worker.port);
const transport = new WorkerTransport(messageHandler, task, networkStream, transportParams, transportFactory);
task._transport = transport;
messageHandler.send("Ready", null);
}).catch(task._capability.reject);
function getUrlProp(val) {
if (val instanceof URL) {
return new URL(val, window.location).href;
if (isNodeJS && typeof val === "string") {
throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
function getDataProp(val) {
if (isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
if (typeof val === "string") {
return stringToBytes(val);
if (val instanceof ArrayBuffer || ArrayBuffer.isView(val) || typeof val === "object" && !isNaN(val?.length)) {
return new Uint8Array(val);
throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
function isRefProxy(ref) {
return typeof ref === "object" && Number.isInteger(ref?.num) && ref.num >= 0 && Number.isInteger(ref?.gen) && ref.gen >= 0;
class PDFDocumentLoadingTask {
this._capability = Promise.withResolvers();
this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
return this._capability.promise;
if (this._worker?.port) {
this._worker._pendingDestroy = true;
await this._transport?.destroy();
if (this._worker?.port) {
delete this._worker._pendingDestroy;
class PDFDataRangeTransport {
constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
this.initialData = initialData;
this.progressiveDone = progressiveDone;
this.contentDispositionFilename = contentDispositionFilename;
this._rangeListeners = [];
this._progressListeners = [];
this._progressiveReadListeners = [];
this._progressiveDoneListeners = [];
this._readyCapability = Promise.withResolvers();
addRangeListener(listener) {
this._rangeListeners.push(listener);
addProgressListener(listener) {
this._progressListeners.push(listener);
addProgressiveReadListener(listener) {
this._progressiveReadListeners.push(listener);
addProgressiveDoneListener(listener) {
this._progressiveDoneListeners.push(listener);
onDataRange(begin, chunk) {
for (const listener of this._rangeListeners) {
onDataProgress(loaded, total) {
this._readyCapability.promise.then(() => {
for (const listener of this._progressListeners) {
onDataProgressiveRead(chunk) {
this._readyCapability.promise.then(() => {
for (const listener of this._progressiveReadListeners) {
onDataProgressiveDone() {
this._readyCapability.promise.then(() => {
for (const listener of this._progressiveDoneListeners) {
this._readyCapability.resolve();
requestDataRange(begin, end) {
unreachable("Abstract method PDFDataRangeTransport.requestDataRange");
constructor(pdfInfo, transport) {
this._transport = transport;
get annotationStorage() {
return this._transport.annotationStorage;
return this._transport.filterFactory;
return this._pdfInfo.numPages;
return this._pdfInfo.fingerprints;
return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
return this._transport._htmlForXfa;
return this._transport.getPage(pageNumber);
return this._transport.getPageIndex(ref);
return this._transport.getDestinations();
return this._transport.getDestination(id);
return this._transport.getPageLabels();
return this._transport.getPageLayout();
return this._transport.getPageMode();
return this._transport.getViewerPreferences();
return this._transport.getOpenAction();
return this._transport.getAttachments();
return this._transport.getDocJSActions();
return this._transport.getOutline();
getOptionalContentConfig({
} = this._transport.getRenderingIntent(intent);
return this._transport.getOptionalContentConfig(renderingIntent);
return this._transport.getPermissions();
return this._transport.getMetadata();
return this._transport.getMarkInfo();
return this._transport.getData();
return this._transport.saveDocument();
return this._transport.downloadInfoCapability.promise;
cleanup(keepLoadedFonts = false) {
return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
return this.loadingTask.destroy();
return this._transport.cachedPageNumber(ref);
return this._transport.loadingParams;
return this._transport.loadingTask;
return this._transport.getFieldObjects();
return this._transport.hasJSActions();
getCalculationOrderIds() {
return this._transport.getCalculationOrderIds();
#delayedCleanupTimeout = null;
constructor(pageIndex, pageInfo, transport, pdfBug = false) {
this._pageIndex = pageIndex;
this._pageInfo = pageInfo;
this._transport = transport;
this._stats = pdfBug ? new StatTimer() : null;
this.commonObjs = transport.commonObjs;
this.objs = new PDFObjects();
this._maybeCleanupAfterRender = false;
this._intentStates = new Map();
return this._pageIndex + 1;
return this._pageInfo.rotate;
return this._pageInfo.ref;
return this._pageInfo.userUnit;
return this._pageInfo.view;
return new PageViewport({
} = this._transport.getRenderingIntent(intent);
return this._transport.getAnnotations(this._pageIndex, renderingIntent);
return this._transport.getPageJSActions(this._pageIndex);
return this._transport.filterFactory;
return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
return this._transport._htmlForXfa?.children[this._pageIndex] || null;
annotationMode = AnnotationMode.ENABLE,
optionalContentConfigPromise = null,
annotationCanvasMap = null,
printAnnotationStorage = null
this._stats?.time("Overall");
const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
this.#pendingCleanup = false;
this.#abortDelayedCleanup();
optionalContentConfigPromise ||= this._transport.getOptionalContentConfig(renderingIntent);
let intentState = this._intentStates.get(cacheKey);
intentState = Object.create(null);
this._intentStates.set(cacheKey, intentState);
if (intentState.streamReaderCancelTimeout) {
clearTimeout(intentState.streamReaderCancelTimeout);
intentState.streamReaderCancelTimeout = null;
const intentPrint = !!(renderingIntent & RenderingIntentFlag.PRINT);
if (!intentState.displayReadyCapability) {
intentState.displayReadyCapability = Promise.withResolvers();
intentState.operatorList = {
this._stats?.time("Page Request");
this._pumpOperatorList(intentArgs);
const complete = error => {