Stamp excluded pages

This commit is contained in:
Adina Țeudan 2021-07-13 18:46:57 +03:00
parent 7ef6b208a6
commit 483bd71c2f
9 changed files with 74 additions and 41 deletions

View File

@ -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();

View File

@ -142,7 +142,9 @@
redactionHasScrollbar
tabindex="1"
>
<ng-container *ngIf="!displayedAnnotations[activeViewerPage]">
<ng-container
*ngIf="activeViewerPage && !displayedAnnotations[activeViewerPage]"
>
<redaction-empty-state
[horizontalPadding]="24"
[verticalPadding]="40"
@ -157,7 +159,7 @@
{{ 'file-preview.tabs.annotations.page-is' | translate }}
<a
(click)="actionPerformed.emit('view-exclude-pages')"
translate="file-preview.tabs.annotations.excluded-from-redaction"
translate="file-preview.excluded-from-redaction"
>
</a
>.

View File

@ -16,7 +16,7 @@
<div>
<input
#pageInput
(change)="utils.navigateToPageByInput(pageInput.value)"
(change)="utils.navigateToPage(pageInput.value)"
[max]="utils.totalPages"
[value]="utils.currentPage"
class="page-number-input"

View File

@ -150,8 +150,8 @@ export class PdfViewerComponent implements OnInit, OnChanges {
() => {
this.viewMode = 'COMPARE';
},
(page: number) => {
this.utils.navigateToPage(page);
() => {
this.utils.navigateToPage(1);
},
PDFNet
);

View File

@ -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()))

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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",