Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to generate PDF using jQuery?

Tags:

jquery

pdf

I am using Ajax functionality to retrieve my content and I need to export PDF on success of jQuery.ajax(). How can I do that?

like image 449
Mohan Ram Avatar asked Dec 20 '10 13:12

Mohan Ram


People also ask

How can create HTML PDF in jQuery?

Explanation: The Export Button has been assigned a jQuery click event handler. When the Export Button is clicked, the HTML Table is converted into a HTML5 Canvas using html2canvas plugin and then the HTML5 Canvas will be exported to PDF using the pdfmake plugin.

Is it possible to save HTML page as PDF using JavaScript or jQuery?

If you want a client-side solution to generate PDF document, JavaScript is the easiest way to convert HTML to PDF. There are various JavaScript library is available to generate PDF from HTML. The jsPDF is one of the best library to convert HTML to PDF using JavaScript.

How can download PDF with button click in jQuery?

Downloading PDF File on Button Click using jQuery Inside the DownloadFile JavaScript function, the URL of the File is passed as parameter to the jQuery AJAX function. Inside the jQuery AJAX function, using the XmlHttpRequest (XHR) call, the PDF file is downloaded as Byte Array (Binary Data).


2 Answers

jQuery cannot (because JavaScript cannot) create a PDF from data, no...it can get one from your server (like any other request), but it cannot generate one. JavaScript simply doesn't have a mechanism (though there are some HTML5 options being implemented now) to create/save a file that works cross-browser, especially a binary file.

like image 192
Nick Craver Avatar answered Oct 08 '22 01:10

Nick Craver


If at all possible, the server-side is a better choice for generating PDFs. It's probably going to be faster for most users and returning a file via standard HTTP request is much more robust than the current client-side options.

That said, this library will generate a PDF on the client-side: http://snapshotmedia.co.uk/blog/jspdf

In browsers that support data URIs, it can return the PDF directly. In other browsers, you can couple it with a Flash component called Downloadify to accomplish the same.

like image 21
Dave Ward Avatar answered Oct 08 '22 01:10

Dave Ward