diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index e1ff87b30..53169bc96 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -257,7 +257,6 @@ export class FilePreviewScreenComponent } } - await this._stampService.stampPDF(); this.#rebuildFilters(); } @@ -602,7 +601,9 @@ export class FilePreviewScreenComponent .pipe(tap(() => this._handleDeletedFile())) .subscribe(); - this.addActiveScreenSubscription = combineLatest([this._viewModeService.viewMode$, this.state.file$]) + const viewModeChanged$ = this._viewModeService.viewMode$.pipe(tap(() => this._stampService.stampPDF().then())); + + this.addActiveScreenSubscription = combineLatest([viewModeChanged$, this.state.file$]) .pipe( filter(([viewMode, file]) => viewMode === ViewModes.TEXT_HIGHLIGHTS && !file.hasHighlights), tap(() => this._viewModeService.switchToStandard()), diff --git a/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts b/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts index e90abcf28..f9ff41197 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts @@ -31,6 +31,7 @@ export class StampService { const file = this._state.file; const allPages = [...Array(file.numberOfPages).keys()].map(page => page + 1); + await pdfDoc.lock(); try { await clearStamps(pdfDoc, this._pdf.PDFNet, allPages, this._licenseService.activeLicenseKey); } catch (e) { @@ -47,7 +48,8 @@ export class StampService { await this._stampExcludedPages(pdfDoc, file.excludedPages); } - this._documentViewer.refreshAndUpdateView(); + this._documentViewer.refreshAndUpdateView(Array.from({ length: await pdfDoc.getPageCount() }, (_x, i) => i + 1)); + await pdfDoc.unlock(); } private async _stampExcludedPages(document: PDFNet.PDFDoc, excludedPages: number[]): Promise { diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts index cca642fef..f73e9cd4a 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts @@ -153,11 +153,11 @@ export class REDDocumentViewer { } } - refreshAndUpdateView() { + refreshAndUpdateView(visiblePages: number[]) { this.#document.refreshAll(); // do not adjust this page if is compare mode const currentPage = this.#document.getCurrentPage(); - this.#document.updateView([currentPage], currentPage); + this.#document.updateView(visiblePages, currentPage); } resetRotation(pages: number | number[] | string | string[]) {