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