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

Accepted answer
Score: 15

Here's a little snippet which works locally 4 - you can change to suitable your host set 3 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 2 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 1 can be found here: http://snapshotmedia.co.uk/blog/jspdf

More Related questions