From 483bd71c2f4998961bc9b96f2c79ee2d6eb65bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Tue, 13 Jul 2021 18:46:57 +0300 Subject: [PATCH] Stamp excluded pages --- .../watermark/watermark-screen.component.ts | 16 ++++----- .../file-workload.component.html | 6 ++-- .../pdf-viewer/pdf-viewer.component.html | 2 +- .../pdf-viewer/pdf-viewer.component.ts | 4 +-- .../file-preview-screen.component.ts | 34 +++++++++++++++++-- .../dossier/utils/compare-mode.utils.ts | 4 +-- .../modules/dossier/utils/pdf-viewer.utils.ts | 25 +++++++------- apps/red-ui/src/app/utils/page-stamper.ts | 20 ++++++----- apps/red-ui/src/assets/i18n/en.json | 4 +-- 9 files changed, 74 insertions(+), 41 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen.component.ts index 4b489fa1c..78b5ad95e 100644 --- a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen.component.ts @@ -70,8 +70,8 @@ export class WatermarkScreenComponent implements OnInit { } @debounce() - configChanged() { - this._drawWatermark(); + async configChanged() { + await this._drawWatermark(); } save() { @@ -111,17 +111,17 @@ export class WatermarkScreenComponent implements OnInit { ); } - revert() { + async revert() { this.configForm.setValue({ ...this._watermark }); - this.configChanged(); + await this.configChanged(); } triggerChanges() {} - setValue(type: 'fontType' | 'orientation' | 'hexColor', value: any) { + async setValue(type: 'fontType' | 'orientation' | 'hexColor', value: any) { if (!this.configForm.get(type).disabled) { this.configForm.get(type).setValue(value); - this.configChanged(); + await this.configChanged(); } } @@ -157,9 +157,9 @@ export class WatermarkScreenComponent implements OnInit { ).then(instance => { this._instance = instance; - instance.docViewer.on('documentLoaded', () => { + instance.docViewer.on('documentLoaded', async () => { this.viewReady = true; - this._drawWatermark(); + await this._drawWatermark(); }); this._disableElements(); diff --git a/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html index 0cb15a7bd..c44947014 100644 --- a/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/dossier/components/file-workload/file-workload.component.html @@ -142,7 +142,9 @@ redactionHasScrollbar tabindex="1" > - + . diff --git a/apps/red-ui/src/app/modules/dossier/components/pdf-viewer/pdf-viewer.component.html b/apps/red-ui/src/app/modules/dossier/components/pdf-viewer/pdf-viewer.component.html index 5bfe10c73..bcfbe8777 100644 --- a/apps/red-ui/src/app/modules/dossier/components/pdf-viewer/pdf-viewer.component.html +++ b/apps/red-ui/src/app/modules/dossier/components/pdf-viewer/pdf-viewer.component.html @@ -16,7 +16,7 @@
{ this.viewMode = 'COMPARE'; }, - (page: number) => { - this.utils.navigateToPage(page); + () => { + this.utils.navigateToPage(1); }, PDFNet ); diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 5e84a15f5..7ce682727 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -46,6 +46,8 @@ import { processFilters } from '@shared/components/filters/popup-filter/utils/filter-utils'; import { LoadingService } from '../../../../services/loading.service'; +import { stampPDFPage } from '../../../../utils/page-stamper'; +import { TranslateService } from '@ngx-translate/core'; const ALL_HOTKEY_ARRAY = ['Escape', 'F', 'f']; @@ -96,7 +98,8 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, private readonly _statusControllerService: StatusControllerService, private readonly _ngZone: NgZone, private readonly _fileManagementControllerService: FileManagementControllerService, - private readonly _loadingService: LoadingService + private readonly _loadingService: LoadingService, + private readonly _translateService: TranslateService ) { document.documentElement.addEventListener('fullscreenchange', () => { if (!document.fullscreenElement) { @@ -361,7 +364,7 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, } selectPage(pageNumber: number) { - this.viewerComponent.utils.navigateToPageByInput(pageNumber); + this.viewerComponent.utils.navigateToPage(pageNumber); this._workloadComponent?.scrollAnnotationsToPage(pageNumber, 'always'); } @@ -447,8 +450,9 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, this._changeDetectorRef.detectChanges(); } - viewerReady($event: WebViewerInstance) { + async viewerReady($event: WebViewerInstance) { this._instance = $event; + await this._stampExcludedPages(); this._cleanupAndRedrawManualAnnotations(); this._updateCanPerformActions(); this.viewReady = true; @@ -570,6 +574,30 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, window.open(`/html-debug/${this.dossierId}/${this.fileId}`, '_blank'); } + private async _stampPage(page: number) { + const document = await this._instance.docViewer.getDocument().getPDFDoc(); + await stampPDFPage( + document, + this._instance.PDFNet, + this._translateService.instant('file-preview.excluded-from-redaction'), + 25, + 'courier', + 'DIAGONAL', + 33, + '#283241', + page + ); + } + + private async _stampExcludedPages() { + for (const page of this.fileData.fileStatus.excludedPages) { + await this._stampPage(page); + } + this._instance.docViewer.refreshAll(); + this._instance.docViewer.updateView([this.activeViewerPage], this.activeViewerPage); + this._changeDetectorRef.detectChanges(); + } + private _subscribeToFileUpdates(): void { this.filesAutoUpdateTimer = timer(0, 5000) .pipe(tap(async () => await this.appStateService.reloadActiveFile())) diff --git a/apps/red-ui/src/app/modules/dossier/utils/compare-mode.utils.ts b/apps/red-ui/src/app/modules/dossier/utils/compare-mode.utils.ts index d1452b7ce..24b130efb 100644 --- a/apps/red-ui/src/app/modules/dossier/utils/compare-mode.utils.ts +++ b/apps/red-ui/src/app/modules/dossier/utils/compare-mode.utils.ts @@ -38,7 +38,7 @@ export const loadCompareDocumentWrapper = async ( instance, fileStatus, setCompareViewMode: () => void, - navigateToPage: (number) => void, + navigateToPage: () => void, PDFNet ) => { try { @@ -65,7 +65,7 @@ export const loadCompareDocumentWrapper = async ( instance.disableElements(['compareButton']); instance.enableElements(['closeCompareButton']); - navigateToPage(1); + navigateToPage(); } catch (e) { console.error(e); } diff --git a/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts b/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts index fac4cb793..f13aea3da 100644 --- a/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts +++ b/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts @@ -91,28 +91,22 @@ export class PdfViewerUtils { return this.instance?.docViewer?.getPageCount(); } - navigateToPage(pageNumber) { - const activePage = this.instance.docViewer.getCurrentPage(); - if (activePage !== pageNumber) { - this.instance.docViewer.displayPageLocation(pageNumber, 0, 0); - } - } - - navigateToPageByInput(pageNumber) { - this.navigateToPage( - this.paginationOffset === 2 ? pageNumber * this.paginationOffset - 1 : pageNumber + navigateToPage(pageNumber: string | number) { + const parsedNumber = typeof pageNumber === 'string' ? parseInt(pageNumber, 10) : pageNumber; + this._navigateToPage( + this.paginationOffset === 2 ? parsedNumber * this.paginationOffset - 1 : parsedNumber ); } previousPage() { if (this._currentInternalPage > 1) { - this.navigateToPage(Math.max(this._currentInternalPage - this.paginationOffset, 1)); + this._navigateToPage(Math.max(this._currentInternalPage - this.paginationOffset, 1)); } } nextPage() { if (this._currentInternalPage < this._totalInternalPages) { - this.navigateToPage( + this._navigateToPage( Math.min( this._currentInternalPage + this.paginationOffset, this._totalInternalPages @@ -178,6 +172,13 @@ export class PdfViewerUtils { this.instance.annotManager.deselectAnnotations(ann); } + private _navigateToPage(pageNumber) { + const activePage = this.instance.docViewer.getCurrentPage(); + if (activePage !== pageNumber) { + this.instance.docViewer.displayPageLocation(pageNumber, 0, 0); + } + } + private _getAnnotationById(id: string): Annotations.Annotation { return this.instance.annotManager.getAnnotationById(id); } diff --git a/apps/red-ui/src/app/utils/page-stamper.ts b/apps/red-ui/src/app/utils/page-stamper.ts index 0f33510e5..e2c444ae5 100644 --- a/apps/red-ui/src/app/utils/page-stamper.ts +++ b/apps/red-ui/src/app/utils/page-stamper.ts @@ -1,30 +1,32 @@ import { hexToRgb } from './functions'; import { environment } from '../../environments/environment'; +import { PDFNet } from '@pdftron/webviewer'; +import PDFDoc = PDFNet.PDFDoc; export async function stampPDFPage( - document: any, - PDFNet: any, + document: PDFDoc, + PdfNet: any, text: string, fontSize: number, fontType: string, - orientation: string, + orientation: 'DIAGONAL' | 'HORIZONTAL' | 'VERTICAL', opacity: number, color: string, page: number ) { - await PDFNet.runWithCleanup( + await PdfNet.runWithCleanup( async () => { await document.lock(); - const pageSet = await PDFNet.PageSet.createSinglePage(page); + const pageSet = await PdfNet.PageSet.createSinglePage(page); - await PDFNet.Stamper.deleteStamps(document, pageSet); + await PdfNet.Stamper.deleteStamps(document, pageSet); const rgbColor = hexToRgb(color); - const stamper = await PDFNet.Stamper.create(3, fontSize, 0); + const stamper = await PdfNet.Stamper.create(3, fontSize, 0); await stamper.setFontColor( - await PDFNet.ColorPt.init(rgbColor.r / 255, rgbColor.g / 255, rgbColor.b / 255) + await PdfNet.ColorPt.init(rgbColor.r / 255, rgbColor.g / 255, rgbColor.b / 255) ); await stamper.setOpacity(opacity / 100); @@ -41,7 +43,7 @@ export async function stampPDFPage( await stamper.setRotation(-45); } - const font = await PDFNet.Font.createAndEmbed(document, convertFont(fontType)); + const font = await PdfNet.Font.createAndEmbed(document, convertFont(fontType)); await stamper.setFont(font); await stamper.setTextAlignment(0); await stamper.stampText(document, text, pageSet); diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index ae0fe1ad9..c8308f232 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -923,6 +923,7 @@ "document-info": "Your Document Info lives here. This includes metadata required on each document.", "download-original-file": "Download Original File", "exclude-pages": "Exclude pages from redaction", + "excluded-from-redaction": "excluded from redaction", "fullscreen": "Full Screen (F)", "html-debug": "Open Document HTML Debug", "last-reviewer": "Last Reviewed by:", @@ -949,8 +950,7 @@ "select": "Select", "select-all": "All", "select-none": "None", - "page-is": "This page is", - "excluded-from-redaction": "excluded from redaction" + "page-is": "This page is" }, "document-info": { "close": "Close Document Info",