update pdfviewer utils

This commit is contained in:
Dan Percic 2021-09-12 12:23:34 +03:00
parent f40c67337a
commit c8a63b9aa4

View File

@ -1,4 +1,3 @@
// import { Annotations, WebViewerInstance } from '@pdftron/webviewer';
import { ViewMode } from '@models/file/view-mode';
import { translateQuads } from '@utils/pdf-coordinates';
import { Rectangle } from '@redaction/red-ui-http';
@ -37,18 +36,19 @@ const DISABLED_HOTKEYS = [
'H',
'K',
'U'
];
] as const;
export class PdfViewerUtils {
instance: WebViewerInstance;
viewMode: ViewMode;
ready = false;
multiSelectActive: boolean;
constructor(instance: WebViewerInstance, viewMode: ViewMode, multiSelectActive: boolean) {
this.instance = instance;
this.viewMode = viewMode;
this.multiSelectActive = multiSelectActive;
constructor(readonly instance: WebViewerInstance, public viewMode: ViewMode, public multiSelectActive: boolean) {}
private get _documentViewer() {
return this.instance?.Core.documentViewer;
}
private get _annotationManager() {
return this.instance?.Core.annotationManager;
}
get isCompareMode() {
@ -61,9 +61,7 @@ export class PdfViewerUtils {
get currentPage() {
try {
return this.isCompareMode
? Math.ceil(this.instance?.Core.documentViewer?.getCurrentPage() / 2)
: this.instance?.Core.documentViewer?.getCurrentPage();
return this.isCompareMode ? Math.ceil(this._currentInternalPage / 2) : this._currentInternalPage;
} catch (e) {
return null;
}
@ -75,9 +73,7 @@ export class PdfViewerUtils {
}
try {
return this.isCompareMode
? Math.ceil(this.instance?.Core.documentViewer?.getPageCount() / 2)
: this.instance?.Core.documentViewer?.getPageCount();
return this.isCompareMode ? Math.ceil(this._totalInternalPages / 2) : this._totalInternalPages;
} catch (e) {
return null;
}
@ -115,12 +111,12 @@ export class PdfViewerUtils {
}
translateQuads(page: number, quads: any) {
const rotation = this.instance.Core.documentViewer.getCompleteRotation(page);
const rotation = this._documentViewer.getCompleteRotation(page);
return translateQuads(page, rotation, quads);
}
toPosition(page: number, selectedQuad: any): Rectangle {
const pageHeight = this.instance.Core.documentViewer.getPageHeight(page);
const pageHeight = this._documentViewer.getPageHeight(page);
const height = selectedQuad.y2 - selectedQuad.y4;
return {
page: page,
@ -134,7 +130,7 @@ export class PdfViewerUtils {
}
deselectAllAnnotations() {
this.instance.Core.annotationManager.deselectAllAnnotations();
this._annotationManager.deselectAllAnnotations();
}
selectAnnotations($event: AnnotationWrapper[] | { annotations: AnnotationWrapper[]; multiSelect: boolean }) {
@ -153,24 +149,23 @@ export class PdfViewerUtils {
}
const annotationsFromViewer = annotations.map(ann => this._getAnnotationById(ann.id));
this.instance.Core.annotationManager.selectAnnotations(annotationsFromViewer);
this._annotationManager.selectAnnotations(annotationsFromViewer);
// this.navigateToPage(annotations[0].pageNumber*this.paginationOffset);
this.instance.Core.annotationManager.jumpToAnnotation(annotationsFromViewer[0]);
this._annotationManager.jumpToAnnotation(annotationsFromViewer[0]);
}
deselectAnnotations(annotations: AnnotationWrapper[]) {
const ann = annotations.map(a => this._getAnnotationById(a.id));
this.instance.Core.annotationManager.deselectAnnotations(ann);
this._annotationManager.deselectAnnotations(ann);
}
private _navigateToPage(pageNumber) {
const activePage = this.instance.Core.documentViewer.getCurrentPage();
if (activePage !== pageNumber) {
this.instance.Core.documentViewer.displayPageLocation(pageNumber, 0, 0);
if (this._currentInternalPage !== pageNumber) {
this._documentViewer.displayPageLocation(pageNumber, 0, 0);
}
}
private _getAnnotationById(id: string): Annotation {
return this.instance.Core.annotationManager.getAnnotationById(id);
return this._annotationManager.getAnnotationById(id);
}
}