In my application I need to download pdf by parsing HTML on client side itself. For generating pdf on client side I am using jsPdf. Following is my code.
PdfGenerator.java
public static native String createPDF() /*-{
$wnd.createPDF();
}-*/;
entrypoint.html
function createPDF(){
try {
var doc = new jsPDF();
doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a crea');
doc.output('datauri');
var out = doc.output();
var url = 'data:application/pdf;base64,' + Base64.encode(out);
document.location.href = url;
} catch (e) {
return e.message;
}
return "";
};
I have added all the js in my project and defined script as well. But whenever I call this method then it is giving output “sprintf is not defined.”.
Please let me know if I am missing out something.
I guess you forget to add the scripts for
sprintf.jsandbase64 js. AsjsPdf.jsinternally uses both of these js.entrypoint.html
please refer this link http://forums.webhosting.uk.com/web-designing-development/6718-jspdf-generating-your-pdf-web-page-documents-using-javascript.html