Home > Mobile >  How to open PDF that is stored on a hard drive from a Browser
How to open PDF that is stored on a hard drive from a Browser

Time:02-25

I am converting an old Silverlight app over to Blazor Server on .NET Core 6. The app is a customer service app.

One feature is that of viewing a file which is stored on a hard drive. For example, there is a PDF of the Customer Contract that is stored on a shared drive. The path to this file is stored in a database. So in the Silverlight app, the end user could just click on a button that says "View Contract" and using the path to the file, Silverlight would open up the file in Adobe Reader or whatever app the file type was associated with. This feature has worked well.

Now I need to duplicate that feature in Blazor, which of course is just a browser. If the PDF was stored in a database as bytes in SQL Server, it would be easy for the server to fetch the document and then server it to the end user as a document. But it is stored on a shared drive.

How do I serve up the PDF in this scenario?

CodePudding user response:

Well, this turned out to be easier than I thought it was going to be using a PDF Viewer component.

<SfPdfViewerServer DocumentPath="@DocumentPath" Height="100%" Width="1060px" ></SfPdfViewerServer>

 @code{
 private string DocumentPath { get; set; } = @"S:\Path\To\Test.pdf";
 }

Obviously the server must have permissions to access the location of the PDF for this to work. But it works great. This example is a Syncfusion PDF component.

CodePudding user response:

Using SyncFusion means you have to render the component inside a page. I've used both SyncFusion components for rendering PDFs are performance is not ideal. I would rather suggest you add <a target="_blank" href="URI"> to call an endpoint passing N parameters in the querystring. Then, you return the document. That way the streaming is between server and browser and the application is non-blocking.

  • Related