How To Download A Pdf File In Angular 2

Today, I want to talk about the second method that exports data with a pdf file in Angular 2. We can do it in several ways on the server side. It depends on to your web project.  I will show you how to do it in MVC projects. I wrote this code in C#.  Its converting the data to a pdf file. You must add ItextSharp dll files to your references to use this code.


Then we will send the data with our controller method. And file must be send in the httpResponseMessage byteArrayContent. This method will be used as a service in Angular to fetch the file for downloading.

We should prepare an Angular service to get and download the pdf file.  Code below should be in html file.

This code placed in the component code.

You must install file-saver component to save bytestream as an excel file. At the same time, you can do it with this command in node.js “npm install file-saver –save”. You should also have a look at my other post about Download Excel File In Angular2

If you have question do not forget to write from the chat button next to it or from the comment.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *