How to convert a shared html page to pdf using javascript or jquery

I tried to convert a html page with dynamic values ​​into it in pdf, but I can not. I saw the api as jspdf , but that does not fit my needs. Can anyone recommend a Javascript or jQuery library that is suitable for this purpose?

+11
javascript jquery
Aug 24 2018-12-12T00:
source share
1 answer

Here is a small snippet that works locally - you can change it to configure your host:

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 is the jsPDF link: http://code.google.com/p/jspdf

Here is a useful example of 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

+12
Aug 24 2018-12-12T00:
source share



All Articles