Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and download a file in PDF and docx format which is to be created from the data in table in AngularJS?

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.

like image 297
PHPFan Avatar asked Mar 12 '23 18:03

PHPFan


1 Answers

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

like image 164
Gary Avatar answered Apr 08 '23 00:04

Gary