I'm trying to load a pdf from a web api using a Blazor Server Application. It works in development but not on my IIS Windows server. The pdfViewer just spins after the file binary is downloaded. I've tried loading via file and using the base64 string to no avail.
Here is the code behind.
var responseBody = await UserInterface.GetReportData(jsonString);
ReportDocumentPath = "";
//// DocumentPath = "data:application/pdf;base64," + responseBody;
var filename = Path.Combine(@"C:\Temp\Blazor", DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace("/", "").Replace(" ", "")) + ".pdf";
byte bytes = Convert.FromBase64String(responseBody);
System.IO.FileStream stream =
new FileStream(filename, FileMode.CreateNew);
System.IO.BinaryWriter writer =
writer.Write(bytes, 0, bytes.Length);
//ReportDocumentPath = filename;
//ReportDocumentPath = "data:application/pdf;base64," + responseBody;
PdfViewer.Load("data:application/pdf;base64," + responseBody, null);
catch (Exception ex)
spinnerHidden = true;
loadingShow = !spinnerHidden;
NoMatch = ex.InnerException.ToString();
Here is the Blazor markup
<div class="m-0 m-md-2 m-lg-2">Report Viewer<SfPdfViewerServer @ref="@PdfViewer" DocumentPath="@ReportDocumentPath" Height="800px" Width="100%"></SfPdfViewerServer></div>
were unable to reproduce the reported issue with the provided details. We have
shared the sample in which we have tried to reproduce the issue in the below
We need your complete code snippet to load the document as a base64 string and we have provided our own code snippet below.
We were able to load the base64 String provided by you as a PDF document and we have attached the document below.
public void OnClickopen(MouseEventArgs args)
//Reads the contents of the file into a byte array, and then closes the file.
byte byteArray = System.IO.File.ReadAllBytes("wwwroot/data/HTTP Succinctly.pdf");
//Converts the byte array in to base64 string.
string base64String = Convert.ToBase64String(byteArray);
//PDF document will get loaded from the base64 string.
viewer.Load("data:application/pdf;base64," + base64String, null);
public async Task Load()
string base64String =
viewer.Load("data: application / pdf; base64," + base64String, null);
Try this sample and revert to us with the following details, if you have any concerns.
will be helpful for us to analyze further and provide the details.