I have gone through all the suggestions for how to take a byte array stored in SQL Server db as varbinary
and display it as PDF in a Blazor website. I'm successful in ASP.Net with the aspx pages and code behind but I can't seem to find the right combination for Blazor (ShowPDF.razor
and code behind ShowPDF.razor.cs
)
Here is what I have as variants in the code behind:
The aReport.ReportDocument is returning a byte array of aReport.DocumentSize from the DB
FileStreamResult GetPDF()
{
var pdfStream = new System.IO.MemoryStream();
this.rdb = new ReportData();
aReport = rdb.GetWithReport(1);
pdfStream.Write(aReport.ReportDocument, 0, aReport.DocumentSize);
pdfStream.Position = 0;
return new FileStreamResult(pdfStream, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"));
}
OR 2. direct binary array to base 64 encoding:
return Convert.ToBase64String(aReport.ReportDocument);
While those two processes return the data, I'm unable to find how to set up the razor page to show the result. I have tried:
<object src="@Url.Action("GetPDF")"/>
and other variants without success.
Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…