laxman laxman - 1 year ago 126
Javascript Question

how to convert total html page to pdf using javascript or jquery

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?

Answer Source

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;
   os = new FileOutputStream("test.pdf");

   ITextRenderer renderer = new ITextRenderer();
} finally{
   if(os != null) os.close();

Alternatively, here's the link to 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.text(20, 20, 'Do you like that?');

// Output as Data URI

More information can be found here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download