Handle pdf errors when changing docs

This commit is contained in:
shamoon 2024-01-12 22:23:35 -08:00
parent 3dc5213527
commit 2a36c82762

View File

@ -465,33 +465,42 @@ export class PdfViewerComponent
this.clear() this.clear()
this.setupViewer() if (this.pdfViewer) {
this.pdfViewer._resetView()
this.loadingTask = PDFJS.getDocument(this.getDocumentParams()) this.pdfViewer = null
this.loadingTask!.onProgress = (progressData: PDFProgressData) => {
this.onProgress.emit(progressData)
} }
const src = this.src this.setupViewer()
from(this.loadingTask!.promise as Promise<PDFDocumentProxy>) try {
.pipe(takeUntil(this.destroy$)) this.loadingTask = PDFJS.getDocument(this.getDocumentParams())
.subscribe({
next: (pdf) => {
this._pdf = pdf
this.lastLoaded = src
this.afterLoadComplete.emit(pdf) this.loadingTask!.onProgress = (progressData: PDFProgressData) => {
this.resetPdfDocument() this.onProgress.emit(progressData)
}
this.update() const src = this.src
},
error: (error) => { from(this.loadingTask!.promise as Promise<PDFDocumentProxy>)
this.lastLoaded = null .pipe(takeUntil(this.destroy$))
this.onError.emit(error) .subscribe({
}, next: (pdf) => {
}) this._pdf = pdf
this.lastLoaded = src
this.afterLoadComplete.emit(pdf)
this.resetPdfDocument()
this.update()
},
error: (error) => {
this.lastLoaded = null
this.onError.emit(error)
},
})
} catch (e) {
this.onError.emit(e)
}
} }
private update() { private update() {