I'm struggling without success to use jspdf library in order to export html page as pdf file. There is one similar question here but bad answers. The problem is in UTF-8 characters, even I made all my documents utf8. What should I do to make this library (parall.ax/products/jspdf) insert letters such as š,č,ć into pdf?
Here is the link where you can try this problem (http://balkanex.info/test/start.html), or just have a look on my code below and then go to the link. I must say that I am making local app so I cannot user servers advantages.
<!doctype>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="runner.js" charset="utf-8"></script>
<script type="text/javascript" src="script.js" charset="utf-8"></script>
<script type="text/javascript" src="jspdf/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="jspdf/jspdf.js"></script>
<script type="text/javascript" src="jspdf/libs/Deflate/adler32cs.js"></script>
<script type="text/javascript" src="jspdf/libs/FileSaver.js/FileSaver.js"></script>
<script type="text/javascript" src="jspdf/libs/Blob.js/BlobBuilder.js"></script>
<script type="text/javascript" src="jspdf/jspdf.plugin.addimage.js"></script>
<script type="text/javascript" src="jspdf/jspdf.plugin.standard_fonts_metrics.js">
</script>
<script type="text/javascript" src="jspdf/jspdf.plugin.split_text_to_size.js"> </script>
<script type="text/javascript" src="jspdf/jspdf.plugin.from_html.js"></script>
</head>
<body>
<input type="button" id="btn" value="PROCEED TO THE NEX PAGE" onClick="run();pdf();">
</body>
</html>
runner.js
function run() {
document.write('<div id="id1"><input type="text" id="name" value="Čimoki Šitano"></div><br/>');
document.write('<div id="id3">This is the ordinary txt with č and š and ć</div><br/>');
document.write('<button id="pdf">Export in pdf file</button></div>');
}
script.js
function pdf() {
$(function () {
var doc = new jsPDF();
doc.text(35, 25, "Here are the letters š and č and ć and ž");
var specialElementHandlers = {
'body': function (element, renderer) {
return true;
}};
$('#pdf').click(function () {
doc.fromHTML($('#id3').html(), 15, 35, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample.pdf');
});
});
}
This library doesn't support some of these letters. And the developers told that it will be accessible soon.
But, if you want to use these letters, you can make images that will replace some of the problematic letters.
For example, make the image of the letter Č and then, in the specific field you can change the letter with this image. It is quite a work. Therefore, I suggest you to change the library.