Frequently, we have need to save file as a pdf or txt or sls. For save the file we can use file saver in angular.
If I want to use file saver in angular then we need to follow following step.
Step-1:
Install angular file saver using following command.
#bower install angular-file-saver.
Step-2
Include ngFileSaver
module into your project.
Following code to save file as pdf.
function orderPdf(reportId, reportType, orderId){ $http.get('/skulocity/api/v1/crmsfa/orders/pdf?orderId='+orderId+'&reportId='+reportId+'&reportType='+reportType, {responseType: 'arraybuffer'}) .success(function (data) { var file = new Blob([data], {type: reportType}); var fileName = ""; if(fileName.indexOf("pdf")>-1){ fileName = "order_"+orderId+".pdf"; }else if(fileName.indexOf("csv")>-1){ fileName = "order_"+orderId+".csv"; } FileSaver.saveAs(file, fileName); }); }
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Murari Kumar
Murari is a bright Web developer. He has expertise in Java.