Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert total html page to pdf using javascript or jquery [closed]

Tags:

I tried to convert a html page with dynamic values in it's totality to pdf but i can't. I saw some api like jspdf but that doesn't suit my needs. Can anybody recommend a Javascript or jQuery library that fits this purpose?

like image 375
laxman Avatar asked Aug 24 '12 11:08

laxman


People also ask

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 HTML page as PDF using jQuery?

The HTML Table will be first converted into a HTML5 Canvas using html2canvas plugin and then the HTML5 Canvas will be exported to PDF file using the pdfmake plugin in jQuery. The following HTML Markup consists of an HTML Table and a Button. Explanation: The Export Button has been assigned a jQuery click event handler.

How do I convert HTML to PDF automatically?

On a Windows computer, open an HTML web page in Internet Explorer, Google Chrome, or Firefox. On a Mac, open an HTML web page in Firefox. Click the “Convert to PDF” button in the Adobe PDF toolbar to start the PDF conversion. Enter a file name and save your new PDF file in a desired location.


1 Answers

Here's a little snippet which works locally - you can change to suitable your host set up:

URL url = new File("test.html").toURI().toURL(); WebClient webClient = new WebClient();  HtmlPage page = webClient.getPage(url);  OutputStream os = null; try{    os = new FileOutputStream("test.pdf");     ITextRenderer renderer = new ITextRenderer();    renderer.setDocument(page,url.toString());    renderer.layout();    renderer.createPDF(os); } finally{    if(os != null) os.close(); } 

Alternatively, here's the link to jsPDF: http://code.google.com/p/jspdf

Here's a useful example using jsPDF:

var doc = new jsPDF(); doc.text(20, 20, 'Hello world!'); doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.'); doc.addPage(); doc.text(20, 20, 'Do you like that?');  // Output as Data URI doc.output('datauri'); 

More information can be found here: http://snapshotmedia.co.uk/blog/jspdf

like image 116
Tim Dodd Avatar answered Oct 10 '22 02:10

Tim Dodd