From 0174262efda4878923dad8a47dc7df4a3e034d43 Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Wed, 30 Oct 2024 10:52:39 +0100 Subject: [PATCH] Fix PDFs not correctly opening in new tab --- .../asset-viewer-files/asset-viewer-files.component.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/asset-viewer/src/lib/components/asset-viewer-files/asset-viewer-files.component.ts b/libs/asset-viewer/src/lib/components/asset-viewer-files/asset-viewer-files.component.ts index 845d2f33..b8f27c42 100644 --- a/libs/asset-viewer/src/lib/components/asset-viewer-files/asset-viewer-files.component.ts +++ b/libs/asset-viewer/src/lib/components/asset-viewer-files/asset-viewer-files.component.ts @@ -64,14 +64,17 @@ export class AssetViewerFilesComponent implements OnInit, OnDestroy { const key = `${this.assetId}/${file.id}/${downloadType}` as const; this.activeFileDownloads.add(key); this.httpClient.get(`/api/assets/${this.assetId}/files/${file.id}`, { responseType: 'blob' }).subscribe({ - next: (blob) => { + next: async (blob) => { + const isPdf = file.name.endsWith('.pdf'); + if (isPdf) { + blob = await blob.arrayBuffer().then((buffer) => new Blob([buffer], { type: 'application/pdf' })); + } const url = URL.createObjectURL(blob); const anchor = document.createElement('a'); anchor.setAttribute('style', 'display: none'); anchor.href = url; - anchor.rel = 'noopener noreferrer'; - if (downloadType === 'save-file') { + if (!isPdf || downloadType === 'save-file') { anchor.download = file.name; } else { anchor.target = '_blank';