diff --git a/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts b/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts index bb67b5afd..4a6933fcb 100644 --- a/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts +++ b/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts @@ -16,6 +16,7 @@ import {tap} from "rxjs/operators"; import WebViewer, {Annotations, WebViewerInstance} from "@pdftron/webviewer"; import {TranslateService} from "@ngx-translate/core"; import {ViewerSyncService} from "../service/viwer-sync.service"; +import { AnnotationUtils } from '../../../utils/annotation-utils'; @@ -82,9 +83,9 @@ export class PdfViewerComponent implements OnInit, AfterViewInit, OnDestroy { this._viewerSyncService.registerViewer(this.fileType, this.wvInstance); this._configureTextPopup(); this._configureHeader(); - instance.annotManager.on('annotationChanged', (annotations,b,c) => { - if(b === 'add'){ - this.annotationsAdded.emit(annotations); + instance.annotManager.on('annotationChanged', (annotations, action) => { + if(action === 'add'){ + this.annotationsAdded.emit(AnnotationUtils.sortAnnotations(annotations)); } }); diff --git a/apps/red-ui/src/app/utils/annotation-utils.ts b/apps/red-ui/src/app/utils/annotation-utils.ts new file mode 100644 index 000000000..c5881e81d --- /dev/null +++ b/apps/red-ui/src/app/utils/annotation-utils.ts @@ -0,0 +1,18 @@ +import { Annotations } from '@pdftron/webviewer'; + +export class AnnotationUtils { + public static sortAnnotations(annotations: Annotations.Annotation[]): Annotations.Annotation[] { + return annotations.sort((ann1, ann2) => { + if (ann1.getPageNumber() === ann2.getPageNumber()) { + if (ann1.getY() === ann2.getY()) { + if (ann1.getX() === ann2.getY()) { + return 0; + } + return ann1.getX() < ann2.getX() ? -1 : 1; + } + return ann1.getY() < ann2.getY() ? -1 : 1; + } + return ann1.getPageNumber() < ann2.getPageNumber() ? -1 : 1; + }) + } +}