Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/core/viewer/components/pdf-viewer.component.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
};
Expand All @@ -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)
};
Expand Down Expand Up @@ -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) {
Expand Down