admin管理员组文章数量:1394402
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 (.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>
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');
});
});
}
Share
Improve this question
edited Feb 2, 2021 at 13:09
Ali Esmailpor
1,2013 gold badges12 silver badges23 bronze badges
asked Feb 27, 2014 at 21:26
mpavlovic89mpavlovic89
7693 gold badges16 silver badges37 bronze badges
3 Answers
Reset to default 1This 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.
Please checkout the latest version (v1.4.0) of jsPDF. They just started to support unicode, https://github./MrRio/jsPDF/releases/tag/v.1.4.0
jsPDF does not support anything outside the ASCII range. See https://github./MrRio/jsPDF/issues/12
本文标签: javascriptjsPDF library cannot insert utf8 letters into pdfStack Overflow
版权声明:本文标题:javascript - jsPDF library cannot insert utf8 letters into pdf - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744088571a2588995.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论