Hello
In Blazor server I am able to render a PDF using a data url like this:
Razor
<SfPdfViewerServer @ref="PDFViewer" DocumentPath="@DocumentPath">
<Syncfusion.Blazor.PdfViewer.PdfViewerEvents DocumentLoaded="DocumentLoaded"></Syncfusion.Blazor.PdfViewer.PdfViewerEvents>
</SfPdfViewerServer>
Code
DocumentPath = "data:application/pdf;base64," + Convert.ToBase64String(docContent);
In Blazor Wasm I'm attempting to do the same thing (but with different Nuget Packages) like this:
Razor
<SfPdfViewer @ref="PDFViewer" DocumentPath="@DocumentPath" >
<Syncfusion.Blazor.PdfViewer.PdfViewerEvents DocumentLoaded="DocumentLoaded"></Syncfusion.Blazor.PdfViewer.PdfViewerEvents>
</SfPdfViewer>
Code
DocumentPath = "data:application/pdf;base64," + Convert.ToBase64String(docContent);
I get the following message when attemting this:
"Server-side processing to render the PDF files through the web service. You must configure the ServiceURL to proceed with PDF Viewer"
Is it possible to render a data url in Blazor Wasm?
Many thanks
|
<SfPdfViewer DocumentPath="https://www.syncfusion.com/downloads/support/directtrac/general/pd/PDF_Succinctly1631202044" ServiceUrl="https://localhost:44399/pdfviewer" Height="500px" Width="1060px"></SfPdfViewer>
|
|
public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
MemoryStream stream = new MemoryStream();
object jsonResult = new object();
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
if (bool.Parse(jsonObject["isFileName"]))
{
string documentPath = GetDocumentPath(jsonObject["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
stream = new MemoryStream(bytes);
}
else
{
string fileName = jsonObject["document"].Split("://")[0];
if (fileName == "http" || fileName == "https")
{
WebClient webclient = new WebClient();
byte[] pdfDoc = webclient.DownloadData(jsonObject["document"]);
stream = new MemoryStream(pdfDoc);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
jsonResult = pdfviewer.Load(stream, jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
|
Hey Dhivya
Thanks for the information. I don't suppose syncfusion have the same documentation but with a .Net 6.0 Mininmal API instead?
Big ask, I know but thought I would check.
Regards
Hello
My query was not so much about whether it would work in .Net 6.0 it was how you would achieve the same with a Minimal api (new in .Net 6.0). The Minimal API does away with controllers and has simple end points. So I was wondering if you had an example of the above but using a Minimal API.
Thanks
Hey Dhivya
Thanks, but that sample looks like a standard client server api template, not a minimal api. Do you have a sample that uses a minimal api?
Thanks