Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

PDF not recognized as PDF when opened in _self

$
0
0

In my Blazor project, I utilize JavaScript for managing file downloads and displaying PDFs. I transfer a BLOB via interop to JavaScript and subsequently open the browser's PDF viewer. This process functions properly on Firefox, but encounters issues on Chromium based browsers. While the PDF is displayed correctly, Chromium PDF-Viewer's download button identifies the file as "AllFiles" when opened in _self, and only recognizes it as a PDF when opened in _blank.

I have been unable to resolve these issues, and I'm perplexed by the discrepancy in how the same BLOB is perceived as a PDF or not based on whether it's opened in _self or _blank.

Does anyone have insights on how to make _self opening work properly?

//contentType = 'application/pdf'async function handleFile(filename, contentType, data) {    var sUserAg = navigator.userAgent;    const file = new File([data], filename, { type: contentType });    const url = URL.createObjectURL(file);    const anchorElement = document.createElement("a");    document.body.appendChild(anchorElement);    anchorElement.href = url;    anchorElement.target = "_self";    anchorElement.click();    if (sUserAg.indexOf("Firefox") <= -1) {        setTimeout(function () {            URL.revokeObjectURL(url);        }, 600000);    }    else {        setTimeout(function () {            URL.revokeObjectURL(url);        }, 100);    }    anchorElement.remove();}

Viewing all articles
Browse latest Browse all 4839

Trending Articles