: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
optionalContentConfigPromise.then(optionalContentConfig => {
if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
this.#useThumbnailCanvas.directDrawing = true;
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
this.viewport = this.viewport.clone({
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
if (this._isStandalone) {
this._container?.style.setProperty("--scale-factor", this.viewport.scale);
if (this.#hasRestrictedScaling) {
if (this.maxCanvasPixels === 0) {
} else if (this.maxCanvasPixels > 0) {
onlyCssZoom = (Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels;
const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
if (postponeDrawing || onlyCssZoom) {
if (postponeDrawing && !onlyCssZoom && this.renderingState !== RenderingStates.FINISHED) {
keepAnnotationLayer: true,
keepAnnotationEditorLayer: true,
cancelExtraDelay: drawingDelay
this.renderingState = RenderingStates.FINISHED;
this.#useThumbnailCanvas.directDrawing = false;
redrawAnnotationLayer: true,
redrawAnnotationEditorLayer: true,
redrawTextLayer: !postponeDrawing,
hideTextLayer: postponeDrawing
this.eventBus.dispatch("pagerendered", {
timestamp: performance.now(),
if (!this.zoomLayer && !this.canvas.hidden) {
this.zoomLayer = this.canvas.parentNode;
this.zoomLayer.style.position = "absolute";
target: this.zoomLayer.firstChild
keepAnnotationLayer: true,
keepAnnotationEditorLayer: true,
keepAnnotationLayer = false,
keepAnnotationEditorLayer = false,
this.renderTask.cancel(cancelExtraDelay);
if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
if (this.structTreeLayer && !this.textLayer) {
this.structTreeLayer = null;
if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
this.annotationLayer.cancel();
this.annotationLayer = null;
this._annotationCanvasMap = null;
if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
this.annotationEditorLayer.cancel();
this.annotationEditorLayer = null;
if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
this._textHighlighter?.disable();
redrawAnnotationLayer = false,
redrawAnnotationEditorLayer = false,
if (!target.hasAttribute("zooming")) {
target.setAttribute("zooming", true);
style.width = style.height = "";
const originalViewport = this.#viewportMap.get(target);
if (this.viewport !== originalViewport) {
const relativeRotation = this.viewport.rotation - originalViewport.rotation;
const absRotation = Math.abs(relativeRotation);
if (absRotation === 90 || absRotation === 270) {
target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
if (redrawAnnotationLayer && this.annotationLayer) {
this.#renderAnnotationLayer();
if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
this.#renderAnnotationEditorLayer();
if (redrawXfaLayer && this.xfaLayer) {
this.structTreeLayer?.hide();
} else if (redrawTextLayer) {
return this.viewport.width;
return this.viewport.height;
return this.viewport.convertToPdfPoint(x, y);
async #finishRenderTask(renderTask, error = null) {
if (renderTask === this.renderTask) {
if (error instanceof RenderingCancelledException) {
this.#renderError = null;
this.#renderError = error;
this.renderingState = RenderingStates.FINISHED;
this._resetZoomLayer(true);
this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
this.eventBus.dispatch("pagerendered", {
timestamp: performance.now(),
if (this.renderingState !== RenderingStates.INITIAL) {
console.error("Must be in new state before drawing");
this.renderingState = RenderingStates.FINISHED;
throw new Error("pdfPage is not loaded");
this.renderingState = RenderingStates.RUNNING;
const canvasWrapper = document.createElement("div");
canvasWrapper.classList.add("canvasWrapper");
this.#addLayer(canvasWrapper, "canvasWrapper");
if (!this.textLayer && this.#textLayerMode !== TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
this._accessibilityManager ||= new TextAccessibilityManager();
this.textLayer = new TextLayerBuilder({
highlighter: this._textHighlighter,
accessibilityManager: this._accessibilityManager,
enablePermissions: this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
onAppend: textLayerDiv => {
this.#addLayer(textLayerDiv, "textLayer");
if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) {
annotationEditorUIManager,
} = this.#layerProperties;
this._annotationCanvasMap ||= new Map();
this.annotationLayer = new AnnotationLayerBuilder({
imageResourcesPath: this.imageResourcesPath,
renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS,
annotationCanvasMap: this._annotationCanvasMap,
accessibilityManager: this._accessibilityManager,
annotationEditorUIManager,
onAppend: annotationLayerDiv => {
this.#addLayer(annotationLayerDiv, "annotationLayer");
const renderContinueCallback = cont => {
if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
this.renderingState = RenderingStates.PAUSED;
this.renderingState = RenderingStates.RUNNING;
const canvas = document.createElement("canvas");
canvas.setAttribute("role", "presentation");
const hasHCM = !!(pageColors?.background && pageColors?.foreground);
let showCanvas = isLastShow => {
if (!hasHCM || isLastShow) {
canvasWrapper.append(canvas);
const ctx = canvas.getContext("2d", {
const outputScale = this.outputScale = new OutputScale();
if (this.maxCanvasPixels === 0) {
const invScale = 1 / this.scale;
outputScale.sx *= invScale;
outputScale.sy *= invScale;
this.#hasRestrictedScaling = true;
} else if (this.maxCanvasPixels > 0) {
const pixelsInViewport = width * height;
const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
outputScale.sx = maxScale;
outputScale.sy = maxScale;
this.#hasRestrictedScaling = true;
this.#hasRestrictedScaling = false;
const sfx = approximateFraction(outputScale.sx);
const sfy = approximateFraction(outputScale.sy);
canvas.width = roundToDivide(width * outputScale.sx, sfx[0]);
canvas.height = roundToDivide(height * outputScale.sy, sfy[0]);
style.width = roundToDivide(width, sfx[1]) + "px";
style.height = roundToDivide(height, sfy[1]) + "px";
this.#viewportMap.set(canvas, viewport);
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
annotationMode: this.#annotationMode,
optionalContentConfigPromise: this._optionalContentConfigPromise,
annotationCanvasMap: this._annotationCanvasMap,
const renderTask = this.renderTask = pdfPage.render(renderContext);
renderTask.onContinue = renderContinueCallback;
const resultPromise = renderTask.promise.then(async () => {
await this.#finishRenderTask(renderTask);
if (this.annotationLayer) {
await this.#renderAnnotationLayer();
annotationEditorUIManager
} = this.#layerProperties;
if (!annotationEditorUIManager) {
this.drawLayer ||= new DrawLayerBuilder({
await this.#renderDrawLayer();
this.drawLayer.setParent(canvasWrapper);
if (!this.annotationEditorLayer) {
this.annotationEditorLayer = new AnnotationEditorLayerBuilder({
uiManager: annotationEditorUIManager,
accessibilityManager: this._accessibilityManager,
annotationLayer: this.annotationLayer?.annotationLayer,
textLayer: this.textLayer,
drawLayer: this.drawLayer.getDrawLayer(),
onAppend: annotationEditorLayerDiv => {
this.#addLayer(annotationEditorLayerDiv, "annotationEditorLayer");
this.#renderAnnotationEditorLayer();
if (!(error instanceof RenderingCancelledException)) {
return this.#finishRenderTask(renderTask, error);
} = this.#layerProperties;
this.xfaLayer = new XfaLayerBuilder({
div.setAttribute("data-loaded", true);
this.eventBus.dispatch("pagerender", {
this.pageLabel = typeof label === "string" ? label : null;
this.div.setAttribute("data-l10n-args", JSON.stringify({
page: this.pageLabel ?? this.id
if (this.pageLabel !== null) {
this.div.setAttribute("data-page-label", this.pageLabel);
this.div.removeAttribute("data-page-label");
} = this.#useThumbnailCanvas;
return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null;
;// CONCATENATED MODULE: ./web/pdf_viewer.js
const DEFAULT_CACHE_SIZE = 10;
const PagesCountLimit = {
FORCE_SCROLL_MODE_PAGE: 15000,
FORCE_LAZY_PAGE_INIT: 7500,
PAUSE_EAGER_PAGE_INIT: 250
function isValidAnnotationEditorMode(mode) {
return Object.values(AnnotationEditorType).includes(mode) && mode !== AnnotationEditorType.DISABLE;
class PDFPageViewBuffer {
if (buf.size > this.#size) {
this.#destroyFirstView();
resize(newSize, idsToKeep = null) {
for (const view of buf) {
if (idsToKeep.has(view.id)) {
while (buf.size > this.#size) {
this.#destroyFirstView();
return this.#buf.has(view);
const firstView = this.#buf.keys().next().value;
this.#buf.delete(firstView);