[ADF-5347] Viewer - Closing PDF before all pages are loaded causes errors (#6737)

* flatten promises

* Disable pre-fetching of PDF file data

* default options
This commit is contained in:
Cilibiu Bogdan
2021-02-26 16:55:43 +02:00
committed by GitHub
parent 717f928d1c
commit a72fe557b1

View File

@@ -101,6 +101,10 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
} }
private eventBus = new pdfjsViewer.EventBus(); private eventBus = new pdfjsViewer.EventBus();
private pdfjsDefaultOptions = {
disableAutoFetch: true,
disableStream: true
};
constructor( constructor(
private dialog: MatDialog, private dialog: MatDialog,
@@ -141,6 +145,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = async () => { reader.onload = async () => {
const pdfSource: PDFSource = { const pdfSource: PDFSource = {
...this.pdfjsDefaultOptions,
data: reader.result, data: reader.result,
withCredentials: this.appConfigService.get<boolean>('auth.withCredentials', undefined) withCredentials: this.appConfigService.get<boolean>('auth.withCredentials', undefined)
}; };
@@ -152,6 +157,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
const urlFile = changes['urlFile']; const urlFile = changes['urlFile'];
if (urlFile && urlFile.currentValue) { if (urlFile && urlFile.currentValue) {
const pdfSource: PDFSource = { const pdfSource: PDFSource = {
...this.pdfjsDefaultOptions,
url: urlFile.currentValue, url: urlFile.currentValue,
withCredentials: this.appConfigService.get<boolean>('auth.withCredentials', undefined) withCredentials: this.appConfigService.get<boolean>('auth.withCredentials', undefined)
}; };
@@ -183,15 +189,10 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
this.displayPage = 1; this.displayPage = 1;
this.initPDFViewer(pdfDocument); this.initPDFViewer(pdfDocument);
pdfDocument.getPage(1).then(() => { return pdfDocument.getPage(1);
this.scalePage('auto'); })
}, () => { .then(() => this.scalePage('auto'))
this.error.emit(); .catch(() => this.error.emit());
});
}, () => {
this.error.emit();
});
} }
initPDFViewer(pdfDocument: PDFDocumentProxy) { initPDFViewer(pdfDocument: PDFDocumentProxy) {