-3

I am using Angular Material Table, to show data, which i am getting from an API call. The question now is, how can I export the Mat-Table data into a PDF and a CSV on click of a button, any Angular Modules which can help me serve my purpose.

Thanks

Satya ram
  • 29
  • 1
  • 7

1 Answers1

3

So your question covers a number of things, and I'm sure you've googled around already, but I'm going to share some stuff I've used in the past to do similar work.

HTML Table to PDF

I don't think you'll be able to get the same look and feel as Material into a PDF without some sort of screenshot utility or something custom that doesn't exist today. But I found another stack overflow link for a JS library that does something similar. This obviously might have compatibility issues and such with Angular, but I'm sure you could look around and see if something exists that would work nicely with Angular.

Here's the html table -> PDF link:

Download CSV data as file

This one is a little more straightforward. If you already know the data, you can use javascript to convert your array of table data into a UTF-8 encoded string, and using the text/csv MIMETYPE download that data as a file.

Everytime I have to do this I always just go back to the same stack overflow link below for reference.

JavaScript Download CSV StackOverflow

Tony M
  • 451
  • 5
  • 11