Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor : embed shows pdf correctly in Firefox, but empty in Chrome and Edge

I'm using "embed" to show pdf file in Razor component of Blazor Server

<embed src="@showedPdfContent" visible="false" width="1100" height="730" type="application/pdf"/>

public void SetPdfContent(byte[] content)
{
    showedPdfContent = $"data:application/pdf;base64,{Convert.ToBase64String(content)}";
    StateHasChanged();
}

when I run with Firefox, it works correctly to show pdf file. But, when I run with Chrome or Edge, it shows empty.

embed in chrome

I tried to use "object" or "iframe". But they also didn't work as well. Any ideas to this issue?

like image 396
Quang Vinh Tran Avatar asked Jan 30 '26 08:01

Quang Vinh Tran


1 Answers

A iframe, objector embed didn't worked for me in chrome.

As a workaround u can use the Microsoft.JSInterop.IJSRuntime. Convert the pdf to a base64 string and load it with pdf.js.

A example

like image 176
GermanSniper Avatar answered Feb 01 '26 01:02

GermanSniper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!