mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2415] PDF Viewer - open password protected pdf files (#3022)
* pdf password dialog * PDF viewer onPassword test * pdf password dialog * PDF viewer onPassword test * test * test * test * test * test * test * test * fix password test * travis improvements
This commit is contained in:
committed by
Eugenio Romano
parent
2951374cc0
commit
ae8b7419a0
@@ -28,6 +28,8 @@ import {
|
||||
} from '@angular/core';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
import { PdfPasswordDialogComponent } from './pdfViewer-password-dialog';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
declare let PDFJS: any;
|
||||
|
||||
@@ -92,8 +94,10 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
return Math.round(this.currentScale * 100) + '%';
|
||||
}
|
||||
|
||||
constructor(private renderingQueueServices: RenderingQueueServices,
|
||||
private logService: LogService) {
|
||||
constructor(
|
||||
private dialog: MatDialog,
|
||||
private renderingQueueServices: RenderingQueueServices,
|
||||
private logService: LogService) {
|
||||
// needed to preserve "this" context
|
||||
this.onPageChange = this.onPageChange.bind(this);
|
||||
this.onPagesLoaded = this.onPagesLoaded.bind(this);
|
||||
@@ -124,6 +128,10 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
executePdf(src) {
|
||||
this.loadingTask = this.getPDFJS().getDocument(src);
|
||||
|
||||
this.loadingTask.onPassword = (callback, reason) => {
|
||||
this.onPdfPassword(callback, reason);
|
||||
};
|
||||
|
||||
this.loadingTask.onProgress = (progressData) => {
|
||||
let level = progressData.loaded / progressData.total;
|
||||
this.loadingPercent = Math.round(level * 100);
|
||||
@@ -397,6 +405,20 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.displayPage = event.pageNumber;
|
||||
}
|
||||
|
||||
onPdfPassword(callback, reason) {
|
||||
this.dialog
|
||||
.open(PdfPasswordDialogComponent, {
|
||||
width: '400px',
|
||||
disableClose: true,
|
||||
data: { reason }
|
||||
})
|
||||
.afterClosed().subscribe(password => {
|
||||
if (password) {
|
||||
callback(password);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Page Rendered Event
|
||||
*/
|
||||
|
Reference in New Issue
Block a user