|
@@ -2,11 +2,11 @@ import {
|
|
|
createPromiseCapability,
|
|
|
RenderingCancelledException,
|
|
|
setLayerDimensions,
|
|
|
- SVGGraphics,
|
|
|
AbortException
|
|
|
} from "pdfjs-dist/legacy/build/pdf";
|
|
|
import {
|
|
|
DEFAULT_SCALE,
|
|
|
+ PromiseExt,
|
|
|
RendererType,
|
|
|
RenderingStates,
|
|
|
TextLayerMode,
|
|
@@ -23,7 +23,7 @@ import TextSearch from './TextSearch'
|
|
|
|
|
|
import AnnotationManager from "./annotations";
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
-import { convertbase64ToJpgBuffer } from './fileHandler.ts'
|
|
|
+import { convertBase64ToBytes } from './fileHandler.ts'
|
|
|
/**
|
|
|
* @typedef {Object} PDFPageViewOptions
|
|
|
* @property {HTMLDivElement} [container] - The viewer element.
|
|
@@ -34,7 +34,6 @@ import { convertbase64ToJpgBuffer } from './fileHandler.ts'
|
|
|
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
|
|
|
* A promise that is resolved with an {@link OptionalContentConfig} instance.
|
|
|
* The default value is `null`.
|
|
|
- * @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object.
|
|
|
* @property {number} [textLayerMode] - Controls if the text layer used for
|
|
|
* selection and searching is created. The constants from {TextLayerMode}
|
|
|
* should be used. The default value is `TextLayerMode.ENABLE`.
|
|
@@ -73,6 +72,8 @@ class PDFPageView {
|
|
|
regularAnnotations: true,
|
|
|
};
|
|
|
|
|
|
+ #activeSearch = null
|
|
|
+
|
|
|
/**
|
|
|
* @param {PDFPageViewOptions} options
|
|
|
*/
|
|
@@ -112,7 +113,6 @@ class PDFPageView {
|
|
|
this.pageColors = options.pageColors || null;
|
|
|
|
|
|
this.eventBus = options.eventBus;
|
|
|
- this.renderingQueue = options.renderingQueue;
|
|
|
this._annotations = options.annotations
|
|
|
this._annotationsAll = options.annotationsAll
|
|
|
|
|
@@ -130,12 +130,6 @@ class PDFPageView {
|
|
|
this._renderingState = RenderingStates.INITIAL
|
|
|
this.resume = null;
|
|
|
this._renderError = null;
|
|
|
- if (
|
|
|
- typeof PDFJSDev === "undefined" ||
|
|
|
- PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
|
- ) {
|
|
|
- this._isStandalone = !this.renderingQueue?.hasViewer();
|
|
|
- }
|
|
|
|
|
|
this._annotationCanvasMap = null;
|
|
|
|
|
@@ -172,18 +166,10 @@ class PDFPageView {
|
|
|
|
|
|
this.mode = null
|
|
|
|
|
|
- if (
|
|
|
- (typeof PDFJSDev === "undefined" ||
|
|
|
- PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
- this._isStandalone
|
|
|
- ) {
|
|
|
- // Ensure that the various layers always get the correct initial size,
|
|
|
- // see issue 15795.
|
|
|
- container?.style.setProperty(
|
|
|
- "--scale-factor",
|
|
|
- this.scale * PixelsPerInch.PDF_TO_CSS_UNITS
|
|
|
- );
|
|
|
- }
|
|
|
+ container?.style.setProperty(
|
|
|
+ "--scale-factor",
|
|
|
+ this.scale * PixelsPerInch.PDF_TO_CSS_UNITS
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
async pagePressHandle(evt) {
|
|
@@ -238,10 +224,11 @@ class PDFPageView {
|
|
|
lineWidth: signImg.inkParam.width || 1,
|
|
|
color: signImg.inkParam.color || "#000",
|
|
|
date: new Date(),
|
|
|
+ createDate: new Date(),
|
|
|
name: uuidv4()
|
|
|
}
|
|
|
} else {
|
|
|
- const imageData = await convertbase64ToJpgBuffer(imgData)
|
|
|
+ const imageData = await convertBase64ToBytes(imgData)
|
|
|
annotation = {
|
|
|
operate: "add-annot",
|
|
|
type: "stamp",
|
|
@@ -256,6 +243,7 @@ class PDFPageView {
|
|
|
},
|
|
|
targetPage: pageNum,
|
|
|
date: new Date(),
|
|
|
+ createDate: new Date(),
|
|
|
name: uuidv4()
|
|
|
}
|
|
|
}
|
|
@@ -360,6 +348,12 @@ class PDFPageView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ get selectedText() {
|
|
|
+ if (!this.textSelection) return null
|
|
|
+ const selection = this.textSelection._selection
|
|
|
+ return selection ? selection.textContent : null
|
|
|
+ }
|
|
|
+
|
|
|
#setDimensions() {
|
|
|
const { viewport } = this;
|
|
|
if (this.pdfPage) {
|
|
@@ -396,6 +390,7 @@ class PDFPageView {
|
|
|
}
|
|
|
|
|
|
clearSearchResults() {
|
|
|
+ this.searchResults = null
|
|
|
if (this.textSearch) {
|
|
|
this.textSearch.destroy()
|
|
|
}
|
|
@@ -420,22 +415,265 @@ class PDFPageView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ emptyAnnotations() {
|
|
|
+ if (this.compdfAnnotationLayer) {
|
|
|
+ this.compdfAnnotationLayer.emptyAnnotations()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @private
|
|
|
*/
|
|
|
- async _renderAnnotationEditorLayer() {
|
|
|
- let error = null;
|
|
|
- try {
|
|
|
- await this.annotationEditorLayer.render(this.viewport, "display");
|
|
|
- } catch (ex) {
|
|
|
- console.error(`_renderAnnotationEditorLayer: "${ex}".`);
|
|
|
- error = ex;
|
|
|
- } finally {
|
|
|
- this.eventBus.dispatch("annotationeditorlayerrendered", {
|
|
|
- source: this,
|
|
|
- pageNumber: this.id,
|
|
|
- error,
|
|
|
- });
|
|
|
+ _renderAnnotationEditorLayer() {
|
|
|
+ this.annotationEditorLayer.render(this.viewport, "display");
|
|
|
+ }
|
|
|
+
|
|
|
+ renderPage() {
|
|
|
+ if (this.renderingState !== RenderingStates.INITIAL) {
|
|
|
+ console.error("Must be in new state before drawing");
|
|
|
+ this.reset(); // Ensure that we reset all state to prevent issues.
|
|
|
+ }
|
|
|
+ const { div, viewport, pdfPage, annotations, annotationsAll } = this;
|
|
|
+
|
|
|
+ if (!pdfPage) {
|
|
|
+ this.renderingState = RenderingStates.FINISHED;
|
|
|
+ throw new Error("pdfPage is not loaded");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.renderingState = RenderingStates.RUNNING;
|
|
|
+
|
|
|
+ const canvasWrapper = document.createElement("div");
|
|
|
+ canvasWrapper.classList.add("canvasWrapper");
|
|
|
+ div.append(canvasWrapper)
|
|
|
+
|
|
|
+ const canvas = document.createElement("canvas");
|
|
|
+ canvas.setAttribute("role", "presentation");
|
|
|
+
|
|
|
+ canvas.hidden = true;
|
|
|
+ let isCanvasHidden = true;
|
|
|
+ const showCanvas = function () {
|
|
|
+ if (isCanvasHidden) {
|
|
|
+ canvas.hidden = false;
|
|
|
+ isCanvasHidden = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ canvasWrapper.append(canvas);
|
|
|
+ this.canvas = canvas
|
|
|
+
|
|
|
+ const radio = window.devicePixelRatio || 1
|
|
|
+ this.radio = radio
|
|
|
+ const { width, height, scale } = viewport
|
|
|
+
|
|
|
+ const canvasWidth = Math.round(width * radio)
|
|
|
+ const canvasHeight = Math.round(height * radio)
|
|
|
+
|
|
|
+ canvas.width = canvasWidth
|
|
|
+ canvas.height = canvasHeight
|
|
|
+ const { style } = canvas;
|
|
|
+ style.width = Math.round(width) + "px"
|
|
|
+ style.height = Math.round(height) + "px"
|
|
|
+
|
|
|
+ this.paintedViewportMap.set(canvas, viewport)
|
|
|
+
|
|
|
+ const renderTask = (this.renderTask = this.internalRenderTask({
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ scale: scale * radio
|
|
|
+ }))
|
|
|
+
|
|
|
+ const resultPromise = renderTask.promise.then(
|
|
|
+ async () => {
|
|
|
+ showCanvas();
|
|
|
+ await this.finishRenderTask();
|
|
|
+
|
|
|
+ this.#renderTextLayer();
|
|
|
+
|
|
|
+ if (this.annotationLayer) {
|
|
|
+ await this._renderAnnotationLayer();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.annotationEditorLayer) {
|
|
|
+ const { annotationEditorUIManager, annotationStorage } = this.layerProperties();
|
|
|
+
|
|
|
+ if (!annotationEditorUIManager) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.annotationEditorLayer = new PDFAnnotationLayer({
|
|
|
+ uiManager: annotationEditorUIManager,
|
|
|
+ annotationStorage,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ pageDiv: div,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ annotations,
|
|
|
+ accessibilityManager: this._accessibilityManager,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this._renderAnnotationEditorLayer();
|
|
|
+
|
|
|
+ if (!this.compdfAnnotationLayer) {
|
|
|
+ this.compdfAnnotationLayer = new ComPDFAnnotationLayer({
|
|
|
+ annotationStore: this.annotationStore,
|
|
|
+ messageHandler: this.messageHandler,
|
|
|
+ pageViewer: this,
|
|
|
+ annotations,
|
|
|
+ annotationsAll,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ pageDiv: div,
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ selected: this.selected,
|
|
|
+ $t: this.$t
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.compdfAnnotationLayer.render(this.viewport)
|
|
|
+
|
|
|
+ // this.AnnotationManager = new AnnotationManager({
|
|
|
+ // annotations,
|
|
|
+ // container: div,
|
|
|
+ // viewport: this.viewport,
|
|
|
+ // })
|
|
|
+
|
|
|
+ if (!this.contentContainer) {
|
|
|
+ this.contentContainer = new ContentContainer({
|
|
|
+ annotationStore: this.annotationStore,
|
|
|
+ pageViewer: this,
|
|
|
+ annotations,
|
|
|
+ annotationsAll,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ pageDiv: div,
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ selected: this.selected,
|
|
|
+ pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
|
|
|
+ messageHandler: this.messageHandler
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (this.mode === 'editor') {
|
|
|
+ await this.contentContainer.render()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.textSelection) {
|
|
|
+ this.textSelection = new TextSelection({
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ container: div,
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ selected: this.selected,
|
|
|
+ pagePtr: this.pagesPtr[this.pageIndex],
|
|
|
+ messageHandler: this.messageHandler,
|
|
|
+ tool: this.tool,
|
|
|
+ toolMode: this.toolMode,
|
|
|
+ color: this.color,
|
|
|
+ pageViewer: this
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.textSearch) {
|
|
|
+ this.textSearch = new TextSearch({
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ container: div,
|
|
|
+ results: this.searchResults,
|
|
|
+ })
|
|
|
+ if (this.#activeSearch) {
|
|
|
+ this.textSearch.setActiveSearchResult(this.#activeSearch)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error => {
|
|
|
+ console.log(error)
|
|
|
+ return this.finishRenderTask(error);
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ div.setAttribute("data-loaded", true);
|
|
|
+
|
|
|
+ this.eventBus.dispatch("pagerender", {
|
|
|
+ source: this,
|
|
|
+ pageNumber: this.id,
|
|
|
+ });
|
|
|
+ return resultPromise
|
|
|
+ }
|
|
|
+
|
|
|
+ internalRenderTask({
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ scale
|
|
|
+ }) {
|
|
|
+ let renderTask = this.renderTask
|
|
|
+
|
|
|
+ if (renderTask) {
|
|
|
+ renderTask.cancel()
|
|
|
+ }
|
|
|
+
|
|
|
+ renderTask = this.render({
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ scale
|
|
|
+ })
|
|
|
+
|
|
|
+ return renderTask
|
|
|
+ }
|
|
|
+
|
|
|
+ render({
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ scale
|
|
|
+ }) {
|
|
|
+ const renderCapability = new PromiseExt()
|
|
|
+ renderCapability.cancel = function () {
|
|
|
+ renderCapability.reject('Cancel')
|
|
|
+ }
|
|
|
+ const { canvas, pagesPtr, pageIndex } = this
|
|
|
+
|
|
|
+ this.messageHandler.sendWithPromise('PushRenderTask', {
|
|
|
+ pagePtr: pagesPtr[pageIndex].pagePtr,
|
|
|
+ left: 0,
|
|
|
+ top: 0,
|
|
|
+ right: Math.round(width),
|
|
|
+ bottom: Math.round(height),
|
|
|
+ scale
|
|
|
+ })
|
|
|
+ .then((data) => {
|
|
|
+ const ctx = canvas.getContext("2d", { alpha: false });
|
|
|
+ const { imageArray } = data
|
|
|
+ ctx.clearRect(0, 0, width, height)
|
|
|
+ let imageData = ctx.createImageData(width, height);
|
|
|
+ imageData.data.set(imageArray)
|
|
|
+ ctx.putImageData(imageData, 0, 0)
|
|
|
+
|
|
|
+ renderCapability.resolve()
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ return renderCapability
|
|
|
+ }
|
|
|
+
|
|
|
+ finishRenderTask (error = null) {
|
|
|
+ this.renderTask = null
|
|
|
+
|
|
|
+ this._renderError = error;
|
|
|
+
|
|
|
+ this.renderingState = RenderingStates.FINISHED;
|
|
|
+ this._resetZoomLayer(/* removeFromDOM = */ true);
|
|
|
+
|
|
|
+ this.eventBus.dispatch("pagerendered", {
|
|
|
+ source: this,
|
|
|
+ pageNumber: this.id,
|
|
|
+ cssTransform: false,
|
|
|
+ timestamp: performance.now(),
|
|
|
+ error: this._renderError,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (error) {
|
|
|
+ throw error;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -513,18 +751,16 @@ class PDFPageView {
|
|
|
(keepAnnotationLayer && this.annotationLayer?.div) || null,
|
|
|
annotationEditorLayerNode =
|
|
|
(keepAnnotationEditorLayer && this.annotationEditorLayer?.div) || null,
|
|
|
- xfaLayerNode = (keepXfaLayer && this.xfaLayer?.div) || null,
|
|
|
textLayerNode = (keepTextLayer && this.textLayer?.div) || null
|
|
|
+
|
|
|
for (let i = childNodes.length - 1; i >= 0; i--) {
|
|
|
const node = childNodes[i];
|
|
|
switch (node) {
|
|
|
case zoomLayerNode:
|
|
|
- case xfaLayerNode:
|
|
|
case textLayerNode:
|
|
|
continue;
|
|
|
case annotationLayerNode:
|
|
|
case annotationEditorLayerNode:
|
|
|
- const annotationChildNodes = node.childNodes
|
|
|
continue;
|
|
|
}
|
|
|
node.remove();
|
|
@@ -542,11 +778,6 @@ class PDFPageView {
|
|
|
} else {
|
|
|
this.annotationEditorLayer?.destroy();
|
|
|
}
|
|
|
- if (xfaLayerNode) {
|
|
|
- // Hide the XFA layer until all elements are resized
|
|
|
- // so they are not displayed on the already resized page.
|
|
|
- this.xfaLayer.hide();
|
|
|
- }
|
|
|
if (textLayerNode) {
|
|
|
this.textLayer.hide();
|
|
|
}
|
|
@@ -563,14 +794,6 @@ class PDFPageView {
|
|
|
}
|
|
|
this._resetZoomLayer();
|
|
|
}
|
|
|
- if (
|
|
|
- (typeof PDFJSDev === "undefined" ||
|
|
|
- PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
- this.svg
|
|
|
- ) {
|
|
|
- this.paintedViewportMap.delete(this.svg);
|
|
|
- delete this.svg;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
update({
|
|
@@ -590,40 +813,10 @@ class PDFPageView {
|
|
|
});
|
|
|
this.#setDimensions();
|
|
|
|
|
|
- if (
|
|
|
- (typeof PDFJSDev === "undefined" ||
|
|
|
- PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
- this._isStandalone
|
|
|
- ) {
|
|
|
- this.div.parentNode?.style.setProperty(
|
|
|
- "--scale-factor",
|
|
|
- this.viewport.scale
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- if (
|
|
|
- (typeof PDFJSDev === "undefined" ||
|
|
|
- PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
- this.svg
|
|
|
- ) {
|
|
|
- this.cssTransform({
|
|
|
- target: this.svg,
|
|
|
- redrawAnnotationLayer: true,
|
|
|
- redrawAnnotationEditorLayer: true,
|
|
|
- redrawXfaLayer: true,
|
|
|
- redrawTextLayer: true,
|
|
|
- });
|
|
|
-
|
|
|
- this.eventBus.dispatch("pagerendered", {
|
|
|
- source: this,
|
|
|
- pageNumber: this.id,
|
|
|
- cssTransform: true,
|
|
|
- timestamp: performance.now(),
|
|
|
- error: this._renderError,
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ this.div.parentNode?.style.setProperty(
|
|
|
+ "--scale-factor",
|
|
|
+ this.viewport.scale
|
|
|
+ )
|
|
|
const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
|
|
|
|
|
|
if (this.canvas) {
|
|
@@ -701,8 +894,6 @@ class PDFPageView {
|
|
|
cancelRendering({
|
|
|
keepAnnotationLayer = false,
|
|
|
keepAnnotationEditorLayer = false,
|
|
|
- keepXfaLayer = false,
|
|
|
- keepTextLayer = false,
|
|
|
cancelExtraDelay = 0,
|
|
|
} = {}) {
|
|
|
if (this.paintTask) {
|
|
@@ -898,19 +1089,6 @@ class PDFPageView {
|
|
|
div.append(canvasWrapper);
|
|
|
|
|
|
let renderContinueCallback = null;
|
|
|
- if (this.renderingQueue) {
|
|
|
- renderContinueCallback = cont => {
|
|
|
- if (!this.renderingQueue.isHighestPriority(this)) {
|
|
|
- this.renderingState = RenderingStates.PAUSED;
|
|
|
- this.resume = () => {
|
|
|
- this.renderingState = RenderingStates.RUNNING;
|
|
|
- cont();
|
|
|
- };
|
|
|
- return;
|
|
|
- }
|
|
|
- cont();
|
|
|
- };
|
|
|
- }
|
|
|
|
|
|
const finishPaintTask = async (error = null) => {
|
|
|
// The paintTask may have been replaced by a new one, so only remove
|
|
@@ -946,107 +1124,114 @@ class PDFPageView {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const paintTask = this.paintOnCanvas(canvasWrapper);
|
|
|
+ const paintTask = this.paintOnCanvas(canvasWrapper)
|
|
|
paintTask.onRenderContinue = renderContinueCallback;
|
|
|
this.paintTask = paintTask;
|
|
|
- const resultPromise = paintTask.then(
|
|
|
- async () => {
|
|
|
- await finishPaintTask(null)
|
|
|
- this.#renderTextLayer();
|
|
|
|
|
|
- if (this.annotationLayer) {
|
|
|
- await this._renderAnnotationLayer();
|
|
|
- }
|
|
|
+ const resultPromise = paintTask.promise.then(
|
|
|
+ () => {
|
|
|
+ return finishPaintTask(null).then(async () => {
|
|
|
+ this.#renderTextLayer();
|
|
|
|
|
|
- if (!this.annotationEditorLayer) {
|
|
|
- const { annotationEditorUIManager, annotationStorage } = this.layerProperties();
|
|
|
+ if (this.annotationLayer) {
|
|
|
+ await this._renderAnnotationLayer();
|
|
|
+ }
|
|
|
|
|
|
- if (!annotationEditorUIManager) {
|
|
|
- return;
|
|
|
+ if (!this.annotationEditorLayer) {
|
|
|
+ const { annotationEditorUIManager, annotationStorage } = this.layerProperties();
|
|
|
+
|
|
|
+ if (!annotationEditorUIManager) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.annotationEditorLayer = new PDFAnnotationLayer({
|
|
|
+ uiManager: annotationEditorUIManager,
|
|
|
+ annotationStorage,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ pageDiv: div,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ annotations,
|
|
|
+ accessibilityManager: this._accessibilityManager,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this._renderAnnotationEditorLayer();
|
|
|
+
|
|
|
+ if (!this.compdfAnnotationLayer) {
|
|
|
+ this.compdfAnnotationLayer = new ComPDFAnnotationLayer({
|
|
|
+ annotationStore: this.annotationStore,
|
|
|
+ messageHandler: this.messageHandler,
|
|
|
+ pageViewer: this,
|
|
|
+ annotations,
|
|
|
+ annotationsAll,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ pageDiv: div,
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ selected: this.selected,
|
|
|
+ $t: this.$t
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.compdfAnnotationLayer.destroy()
|
|
|
+ }
|
|
|
+ this.compdfAnnotationLayer.render(this.viewport)
|
|
|
+
|
|
|
+ // this.AnnotationManager = new AnnotationManager({
|
|
|
+ // annotations,
|
|
|
+ // container: div,
|
|
|
+ // viewport: this.viewport,
|
|
|
+ // })
|
|
|
+
|
|
|
+ if (!this.contentContainer) {
|
|
|
+ this.contentContainer = new ContentContainer({
|
|
|
+ annotationStore: this.annotationStore,
|
|
|
+ pageViewer: this,
|
|
|
+ annotations,
|
|
|
+ annotationsAll,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ pageDiv: div,
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ selected: this.selected,
|
|
|
+ pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
|
|
|
+ messageHandler: this.messageHandler
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (this.mode === 'editor') {
|
|
|
+ await this.contentContainer.render()
|
|
|
}
|
|
|
- this.annotationEditorLayer = new PDFAnnotationLayer({
|
|
|
- uiManager: annotationEditorUIManager,
|
|
|
- annotationStorage,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- pageDiv: div,
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- annotations,
|
|
|
- accessibilityManager: this._accessibilityManager,
|
|
|
- });
|
|
|
- }
|
|
|
- this._renderAnnotationEditorLayer();
|
|
|
-
|
|
|
- if (!this.compdfAnnotationLayer) {
|
|
|
- this.compdfAnnotationLayer = new ComPDFAnnotationLayer({
|
|
|
- annotationStore: this.annotationStore,
|
|
|
- messageHandler: this.messageHandler,
|
|
|
- pageViewer: this,
|
|
|
- annotations,
|
|
|
- annotationsAll,
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- pageDiv: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- $t: this.$t
|
|
|
- })
|
|
|
- }
|
|
|
- this.compdfAnnotationLayer.render(this.viewport)
|
|
|
-
|
|
|
- // this.AnnotationManager = new AnnotationManager({
|
|
|
- // annotations,
|
|
|
- // container: div,
|
|
|
- // viewport: this.viewport,
|
|
|
- // })
|
|
|
-
|
|
|
- if (!this.contentContainer) {
|
|
|
- this.contentContainer = new ContentContainer({
|
|
|
- annotationStore: this.annotationStore,
|
|
|
- pageViewer: this,
|
|
|
- annotations,
|
|
|
- annotationsAll,
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- pageDiv: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
|
|
|
- messageHandler: this.messageHandler
|
|
|
- })
|
|
|
- }
|
|
|
- if (this.mode === 'editor') {
|
|
|
- await this.contentContainer.render()
|
|
|
- }
|
|
|
|
|
|
- if (!this.textSelection) {
|
|
|
- this.textSelection = new TextSelection({
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- container: div,
|
|
|
- eventBus: this.eventBus,
|
|
|
- selected: this.selected,
|
|
|
- pagePtr: this.pagesPtr[this.pageIndex],
|
|
|
- messageHandler: this.messageHandler,
|
|
|
- tool: this.tool,
|
|
|
- toolMode: this.toolMode,
|
|
|
- color: this.color,
|
|
|
- pageViewer: this
|
|
|
- })
|
|
|
- }
|
|
|
+ if (!this.textSelection) {
|
|
|
+ this.textSelection = new TextSelection({
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ container: div,
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ selected: this.selected,
|
|
|
+ pagePtr: this.pagesPtr[this.pageIndex],
|
|
|
+ messageHandler: this.messageHandler,
|
|
|
+ tool: this.tool,
|
|
|
+ toolMode: this.toolMode,
|
|
|
+ color: this.color,
|
|
|
+ pageViewer: this
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- if (!this.textSearch) {
|
|
|
- this.textSearch = new TextSearch({
|
|
|
- viewport: this.viewport,
|
|
|
- scale: this.scale,
|
|
|
- pageIndex: this.pageIndex,
|
|
|
- container: div,
|
|
|
- results: this.searchResults,
|
|
|
- })
|
|
|
- }
|
|
|
+ if (!this.textSearch) {
|
|
|
+ this.textSearch = new TextSearch({
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ pageIndex: this.pageIndex,
|
|
|
+ container: div,
|
|
|
+ results: this.searchResults,
|
|
|
+ })
|
|
|
+ if (this.#activeSearch) {
|
|
|
+ this.textSearch.setActiveSearchResult(this.#activeSearch)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
function (reason) {
|
|
|
return finishPaintTask(reason);
|
|
@@ -1055,29 +1240,13 @@ class PDFPageView {
|
|
|
|
|
|
div.setAttribute("data-loaded", true);
|
|
|
|
|
|
- this.eventBus.dispatch("pagerender", {
|
|
|
- source: this,
|
|
|
- pageNumber: this.id,
|
|
|
- });
|
|
|
return resultPromise;
|
|
|
}
|
|
|
|
|
|
- setActiveSearchResult(search) {
|
|
|
- if (this.textSearch) {
|
|
|
- this.textSearch.setActiveSearchResult(search)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- clearActiveSearchResult(searchResult) {
|
|
|
- if (this.textSearch) {
|
|
|
- this.textSearch.clearActiveSearchResult(searchResult)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async paintOnCanvas(canvasWrapper) {
|
|
|
+ paintOnCanvas(canvasWrapper) {
|
|
|
const renderCapability = createPromiseCapability();
|
|
|
const result = {
|
|
|
- promise: renderCapability,
|
|
|
+ promise: renderCapability.promise,
|
|
|
onRenderContinue(cont) {
|
|
|
cont();
|
|
|
},
|
|
@@ -1126,38 +1295,32 @@ class PDFPageView {
|
|
|
// Add the viewport so it's known what it was originally drawn with.
|
|
|
this.paintedViewportMap.set(canvas, viewport);
|
|
|
|
|
|
- // Rendering area
|
|
|
- const renderTask = this.messageHandler.sendWithPromise('PushRenderTask', {
|
|
|
- pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
|
|
|
- left: 0,
|
|
|
- top: 0,
|
|
|
- right: Math.round(canvasWidth),
|
|
|
- bottom: Math.round(canvasHeight),
|
|
|
- scale: scale * radio
|
|
|
- })
|
|
|
-
|
|
|
- renderTask.onContinue = function (cont) {
|
|
|
- showCanvas();
|
|
|
- if (result.onRenderContinue) {
|
|
|
- result.onRenderContinue(cont);
|
|
|
- } else {
|
|
|
- cont();
|
|
|
- }
|
|
|
- };
|
|
|
+ const renderTask = new PromiseExt()
|
|
|
|
|
|
renderTask.cancel = function() {
|
|
|
}
|
|
|
|
|
|
- renderTask.then(
|
|
|
- function ({ imageArray }) {
|
|
|
+ renderTask.resolve()
|
|
|
+ renderTask.promise.then(
|
|
|
+ async () => {
|
|
|
+ const { imageArray } = await this.messageHandler.sendWithPromise('PushRenderTask', {
|
|
|
+ pagePtr: this.pagesPtr[this.pageIndex].pagePtr,
|
|
|
+ left: 0,
|
|
|
+ top: 0,
|
|
|
+ right: Math.round(canvasWidth),
|
|
|
+ bottom: Math.round(canvasHeight),
|
|
|
+ scale: scale * radio
|
|
|
+ })
|
|
|
ctx.clearRect(0, 0, canvasWidth, canvasHeight)
|
|
|
let imageData = ctx.createImageData(canvasWidth, canvasHeight);
|
|
|
imageData.data.set(imageArray)
|
|
|
ctx.putImageData(imageData, 0, 0)
|
|
|
+
|
|
|
showCanvas();
|
|
|
renderCapability.resolve();
|
|
|
},
|
|
|
function (error) {
|
|
|
+ console.log(error)
|
|
|
// When zooming with a `drawingDelay` set, avoid temporarily showing
|
|
|
// a black canvas if rendering was cancelled before the `onContinue`-
|
|
|
// callback had been invoked at least once.
|
|
@@ -1170,58 +1333,18 @@ class PDFPageView {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- paintOnSvg(wrapper) {
|
|
|
- if (
|
|
|
- !(
|
|
|
- typeof PDFJSDev === "undefined" ||
|
|
|
- PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
|
- )
|
|
|
- ) {
|
|
|
- throw new Error("Not implemented: paintOnSvg");
|
|
|
+ setActiveSearchResult(search) {
|
|
|
+ this.#activeSearch = search
|
|
|
+ if (this.textSearch) {
|
|
|
+ this.textSearch.setActiveSearchResult(search)
|
|
|
}
|
|
|
- let cancelled = false;
|
|
|
- const ensureNotCancelled = () => {
|
|
|
- if (cancelled) {
|
|
|
- throw new RenderingCancelledException(
|
|
|
- `Rendering cancelled, page ${this.id}`,
|
|
|
- "svg"
|
|
|
- );
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- const pdfPage = this.pdfPage;
|
|
|
- const actualSizeViewport = this.viewport.clone({
|
|
|
- scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
|
- });
|
|
|
- const promise = pdfPage
|
|
|
- .getOperatorList()
|
|
|
- .then(opList => {
|
|
|
- ensureNotCancelled();
|
|
|
- const svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
|
|
|
- return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
|
|
|
- ensureNotCancelled();
|
|
|
- this.svg = svg;
|
|
|
- this.paintedViewportMap.set(svg, actualSizeViewport);
|
|
|
-
|
|
|
- svg.style.width = wrapper.style.width;
|
|
|
- svg.style.height = wrapper.style.height;
|
|
|
- this.renderingState = RenderingStates.FINISHED;
|
|
|
- wrapper.append(svg);
|
|
|
- });
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
- return {
|
|
|
- promise,
|
|
|
- onRenderContinue(cont) {
|
|
|
- cont();
|
|
|
- },
|
|
|
- cancel() {
|
|
|
- cancelled = true;
|
|
|
- },
|
|
|
- get separateAnnots() {
|
|
|
- return false;
|
|
|
- },
|
|
|
- };
|
|
|
+ clearActiveSearchResult(searchResult) {
|
|
|
+ this.#activeSearch = null
|
|
|
+ if (this.textSearch) {
|
|
|
+ this.textSearch.clearActiveSearchResult(searchResult)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1242,9 +1365,7 @@ class PDFPageView {
|
|
|
* @ignore
|
|
|
*/
|
|
|
get thumbnailCanvas() {
|
|
|
- const { initialOptionalContent, regularAnnotations } =
|
|
|
- this.#useThumbnailCanvas;
|
|
|
- return initialOptionalContent && regularAnnotations ? this.canvas : null;
|
|
|
+ return this.canvas
|
|
|
}
|
|
|
|
|
|
get fontFile() {
|