: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
this._pagesCapability.resolve();
let getPagesLeft = pagesCount - 1;
this._pagesCapability.resolve();
for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
const pageView = this._pages[pageNum - 1];
pageView.setPdfPage(pdfPage);
if (--getPagesLeft === 0) {
this._pagesCapability.resolve();
console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
if (--getPagesLeft === 0) {
this._pagesCapability.resolve();
if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
eventBus.dispatch("pagesinit", {
pdfDocument.getMetadata().then(({
if (pdfDocument !== this.pdfDocument) {
viewer.lang = info.Language;
if (this.defaultRenderingQueue) {
console.error("Unable to initialize viewer", reason);
this._pagesCapability.reject(reason);
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
console.error(`setPageLabels: Invalid page labels.`);
this._pageLabels = labels;
for (let i = 0, ii = this._pages.length; i < ii; i++) {
this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
this._currentPageNumber = 1;
this._currentScale = UNKNOWN_SCALE;
this._currentScaleValue = null;
this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
this._optionalContentConfigPromise = null;
this._firstPageCapability = Promise.withResolvers();
this._onePageRenderedCapability = Promise.withResolvers();
this._pagesCapability = Promise.withResolvers();
this._scrollMode = ScrollMode.VERTICAL;
this._previousScrollMode = ScrollMode.UNKNOWN;
this._spreadMode = SpreadMode.NONE;
this.#scrollModePageState = {
this.#eventAbortController?.abort();
this.#eventAbortController = null;
this.viewer.textContent = "";
this._updateScrollMode();
this.viewer.removeAttribute("lang");
this.#hiddenCopyElement?.remove();
this.#hiddenCopyElement = null;
#ensurePageViewVisible() {
if (this._scrollMode !== ScrollMode.PAGE) {
throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
const pageNumber = this._currentPageNumber,
state = this.#scrollModePageState,
if (this._spreadMode === SpreadMode.NONE && !this.isInPresentationMode) {
const pageView = this._pages[pageNumber - 1];
viewer.append(pageView.div);
state.pages.push(pageView);
const pageIndexSet = new Set(),
parity = this._spreadMode - 1;
pageIndexSet.add(pageNumber - 1);
} else if (pageNumber % 2 !== parity) {
pageIndexSet.add(pageNumber - 1);
pageIndexSet.add(pageNumber);
pageIndexSet.add(pageNumber - 2);
pageIndexSet.add(pageNumber - 1);
const spread = document.createElement("div");
spread.className = "spread";
if (this.isInPresentationMode) {
const dummyPage = document.createElement("div");
dummyPage.className = "dummyPage";
spread.append(dummyPage);
for (const i of pageIndexSet) {
const pageView = this._pages[i];
spread.append(pageView.div);
state.pages.push(pageView);
state.scrollDown = pageNumber >= state.previousPageNumber;
state.previousPageNumber = pageNumber;
if (this.pagesCount === 0) {
#scrollIntoView(pageView, pageSpot = null) {
if (this._currentPageNumber !== id) {
this._setCurrentPageNumber(id);
if (this._scrollMode === ScrollMode.PAGE) {
this.#ensurePageViewVisible();
if (!pageSpot && !this.isInPresentationMode) {
const left = div.offsetLeft + div.clientLeft,
right = left + div.clientWidth;
if (this._scrollMode === ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
scrollIntoView(div, pageSpot);
if (!this._currentScaleValue && this._location) {
return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
#setScaleUpdatePages(newScale, newValue, {
this._currentScaleValue = newValue.toString();
if (this.#isSameScale(newScale)) {
this.eventBus.dispatch("scalechanging", {
this.viewer.style.setProperty("--scale-factor", newScale * PixelsPerInch.PDF_TO_CSS_UNITS);
const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
drawingDelay: postponeDrawing ? drawingDelay : -1
this.#scaleTimeoutId = setTimeout(() => {
this.#scaleTimeoutId = null;
const previousScale = this._currentScale;
this._currentScale = newScale;
let page = this._currentPageNumber,
if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
page = this._location.pageNumber;
}, this._location.left, this._location.top, null];
this.scrollPageIntoView({
allowNegativeOffset: true
if (Array.isArray(origin)) {
const scaleDiff = newScale / previousScale - 1;
const [top, left] = this.containerTopLeft;
this.container.scrollLeft += (origin[0] - left) * scaleDiff;
this.container.scrollTop += (origin[1] - top) * scaleDiff;
this.eventBus.dispatch("scalechanging", {
presetValue: preset ? newValue : undefined
if (this.defaultRenderingQueue) {
get #pageWidthScaleFactor() {
if (this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL) {
#setScale(value, options) {
let scale = parseFloat(value);
this.#setScaleUpdatePages(scale, value, options);
const currentPage = this._pages[this._currentPageNumber - 1];
let hPadding = SCROLLBAR_PADDING,
vPadding = VERTICAL_PADDING;
if (this.isInPresentationMode) {
if (this._spreadMode !== SpreadMode.NONE) {
} else if (this.removePageBorders) {
} else if (this._scrollMode === ScrollMode.HORIZONTAL) {
[hPadding, vPadding] = [vPadding, hPadding];
const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
scale = Math.min(pageWidthScale, pageHeightScale);
const horizontalScale = isPortraitOrientation(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
console.error(`#setScale: "${value}" is an unknown zoom value.`);
this.#setScaleUpdatePages(scale, value, options);
#resetCurrentPageView() {
const pageView = this._pages[this._currentPageNumber - 1];
if (this.isInPresentationMode) {
this.#setScale(this._currentScaleValue, {
this.#scrollIntoView(pageView);
pageLabelToPageNumber(label) {
const i = this._pageLabels.indexOf(label);
allowNegativeOffset = false,
ignoreDestinationZoom = false
const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
if (this.isInPresentationMode || !destArray) {
this._setCurrentPageNumber(pageNumber, true);
const changeOrientation = pageView.rotation % 180 !== 0;
const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS;
const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS;
switch (destArray[1].name) {
y = y !== null ? y : pageHeight;
if (y === null && this._location) {
} else if (typeof y !== "number" || y < 0) {
width = destArray[4] - x;
height = destArray[5] - y;
let hPadding = SCROLLBAR_PADDING,
vPadding = VERTICAL_PADDING;
if (this.removePageBorders) {
widthScale = (this.container.clientWidth - hPadding) / width / PixelsPerInch.PDF_TO_CSS_UNITS;
heightScale = (this.container.clientHeight - vPadding) / height / PixelsPerInch.PDF_TO_CSS_UNITS;
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
if (!ignoreDestinationZoom) {
if (scale && scale !== this._currentScale) {
this.currentScaleValue = scale;
} else if (this._currentScale === UNKNOWN_SCALE) {
this.currentScaleValue = DEFAULT_SCALE_VALUE;
if (scale === "page-fit" && !destArray[4]) {
this.#scrollIntoView(pageView);
const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
if (!allowNegativeOffset) {
left = Math.max(left, 0);
this.#scrollIntoView(pageView, {
_updateLocation(firstPage) {
const currentScale = this._currentScale;
const currentScaleValue = this._currentScaleValue;
const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
const pageNumber = firstPage.id;
const currentPageView = this._pages[pageNumber - 1];
const container = this.container;
const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
const intLeft = Math.round(topLeft[0]);
const intTop = Math.round(topLeft[1]);
let pdfOpenParams = `#page=${pageNumber}`;
if (!this.isInPresentationMode) {
pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
scale: normalizedScaleValue,
rotation: this._pagesRotation,
const visible = this._getVisiblePages();
const visiblePages = visible.views,
numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
this.#buffer.resize(newCacheSize, visible.ids);
this.renderingQueue.renderHighestPriority(visible);
const isSimpleLayout = this._spreadMode === SpreadMode.NONE && (this._scrollMode === ScrollMode.PAGE || this._scrollMode === ScrollMode.VERTICAL);
const currentId = this._currentPageNumber;
let stillFullyVisible = false;
for (const page of visiblePages) {
if (page.percent < 100) {
if (page.id === currentId && isSimpleLayout) {
stillFullyVisible = true;
this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
this._updateLocation(visible.first);
this.eventBus.dispatch("updateviewarea", {
containsElement(element) {
return this.container.contains(element);
return getComputedStyle(this.container).direction === "rtl";
get isInPresentationMode() {
return this.presentationModeState === PresentationModeState.FULLSCREEN;
get isChangingPresentationMode() {
return this.presentationModeState === PresentationModeState.CHANGING;
get isHorizontalScrollbarEnabled() {
return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
get isVerticalScrollbarEnabled() {
return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
const views = this._scrollMode === ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
horizontal = this._scrollMode === ScrollMode.HORIZONTAL,
rtl = horizontal && this._isContainerRtl;
return getVisibleElements({
scrollEl: this.container,