Reputation: 12957
I'm a newbie to AngularJS and using AngularJS for my web app.
On one page of my web app, I'm fetching data from database and displaying in a table. The data is in JSON format. And, since it contains multiple entries of the same type, it's an array.
I want to provide a Download button to the user and a radio button with the options of .pdf and .docx.
The User will select one of the file formats and click on Download button in order to download the data displayed in table into the selected file format on his/her local machine.
How to achieve it? Can someone please guide me in this regard?
Since the code to fetch and display data in table is too big that's why I haven't given any code snippet here.
If you want I can provide you the same.
If you can explain with some completely working examples for both file formats(.docx and .pdf) in AngularJS it would be really really great to me and other buddies.
Thanks.
Upvotes: 4
Views: 3641
Reputation: 300
Angular UI-Grid has implemented PDF/CSV Export from grid.
Please refer UI-Grid Export Data
They are using Pdfmake to generate PDF of exported data.
Upvotes: 2
Reputation: 2339
There are some few good resources. I use https://mozilla.github.io/pdf.js/ for PDF and https://github.com/evidenceprime/html-docx-js for docx though it needs some manipulations.
Try these that I could find. This is not supposed to be a list of options but each of them have different functionalities. But it surely does not make sense making your own port for these.
PDF http://pdfkit.org/ for extended PDF formatting
https://github.com/tuckerjt07/pdfmake allows for PDF formatting
https://github.com/Prashanth-Nelli/jsPdfTablePlugin Straight forward simple usage
http://github.com/MrRio/jsPDF frequently used
DOCx
http://github.com/MrRio/DOCX.js
https://github.com/evidenceprime/html-docx-js
Upvotes: 4
Reputation: 322
just google for a javascript library that enable you to easily convert your json data to PDF, something like http://github.com/MrRio/jsPDF – Naigel Mar 29 at 9:52
the same person also created this http://github.com/MrRio/DOCX.js – jcubic Mar 29 at 9:54
I'd agree, there's nothing gained from building it yourself unless it's a specialised system, but yours sounds like a very standard way of doing things so it would be far better to use a pre-made system and not waste the time that could be spent better developing the bespoke parts of the system.
Upvotes: 1