BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hello,
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.
SfPdfViewerServer PdfViewer;
try
{
var responseBody = await UserInterface.GetReportData(jsonString);
ReportDocumentPath = "";
//PdfViewer.UnloadAsync();
//// 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 =
new BinaryWriter(stream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
//ReportDocumentPath = filename;
//ReportDocumentPath = "data:application/pdf;base64," + responseBody;
//await PdfViewer.LoadAsync(filename);
PdfViewer.Load("data:application/pdf;base64," + responseBody, null);
StateHasChanged();
}
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>
We
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
link,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/LOAD_Sample_.net_6.0_v_-_20.4.42762790073.zip
Document: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PORTFO~12031110323.zip
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.
Code Snippet:
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.
This
will be helpful for us to analyze further and provide the details.