I'm developing a Chrome App, and i would like to allow the user to export as a PDF a few HTML Table. I made some research and i found jsPdf as the plugin i needed. And now comes my issue. jsPDF and its function "fromHTML" use the method "document.writeln()" which is not available in Chrome Packaged App.
"Uncaught Error: document.writeln() is not available in packaged apps."
Console error as jspdf tries to use document.writeln()
I've made a ton a research over the internet, and found that there are some ways to counter that issue, by adding some "document.create". But while i don't know how jspdf works, i don't really know what to create.
There is the part of jspdf that's causing the issue :
var $frame, $hiddendiv, framename, visuallyhidden;
framename = "jsPDFhtmlText" + Date.now().toString() + (Math.random() * 1000).toFixed(0);
visuallyhidden = "position: absolute !important;" + "clip: rect(1px 1px 1px 1px); /* IE6, IE7 */" + "clip: rect(1px, 1px, 1px, 1px);" + "padding:0 !important;" + "border:0 !important;" + "height: 1px !important;" + "width: 1px !important; " + "top:auto;" + "left:-100px;" + "overflow: hidden;";
$hiddendiv = document.createElement('div');
$hiddendiv.style.cssText = visuallyhidden;
$hiddendiv.innerHTML = "<iframe style=\"height:1px;width:1px\" name=\"" + framename + "\" />";
document.body.appendChild($hiddendiv);
$frame = window.frames[framename];
$frame.document.open();
$frame.document.writeln(element);//This causes "Uncaught Error: document.writeln() is not available in packaged apps."
$frame.document.close();
return $frame.document.body;
And here is my call of the jspdf library, maybe i made a mistake here :
$('#exportMonth').click(function(){
console.log(TAG + "Starting rendering as PDF");
var doc = new jsPDF();
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
// here i've nothing to bypass, so nothing is 'bypassme'
'#bypassme': function(element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
//the id 'month' refers to a div containing a html Table
doc.fromHTML($('#month').html(),15,15 ,{
width:600,
elementHandler:specialElementHandlers
});
doc.save('Tst.pdf');
console.log(TAG + "Should be done");
});
I'll continue my research but i'm really lost rigth now, i really need your help !
I may have forgotten to say some things, just let me know and i'll try to be as quick as possible fixing that.
Many thanks !