Posts

Showing posts from October, 2024

ASP.NET Core 8: Sending PDF Files from ASP.NET Core API to Angular Client and Open the PDF File in Angular Application

Image
In this article, we will implement the mechanism of sending the PDF file from ASP.NET Core API to Angular client application. The Angular client application will download will open this PDF file directly in the browser. It is always important to show the data stored in PDF document from server application to the client application without explicitly downloading it on the client (User may take a call to further save it). In ASP.NET Core we can make use of the Results  class and its File() method to send file from API in the HTTP GET response. This file response can be received by the Angular Client application in the BLOB response type. In the Angular application, we can use the createObjectURL() method of the window.URL interface object to create string URL so that the file can be directly opened in the browser. The Figure 1 shows the implementation type. Figure 1: The Implementation In ASP.NET Core, we cand use the File() method of the Result class to write the Stream into the HTTP Re