javascript jsPDF 库无法将 utf8 字母插入 pdf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22080799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jsPDF library cannot insert utf8 letters into pdf
提问by mpavlovic89
I'm struggling without success to use jspdf libraryin 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?
我正在努力使用jspdf 库将 html 页面导出为 pdf 文件,但没有成功。这里有一个类似的问题,但答案不好。问题出在 UTF-8 字符中,即使我将所有文档都设为 utf8。我应该怎么做才能使这个库(parall.ax/products/jspdf)插入诸如 ?,?,? 变成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.
这是您可以尝试此问题的链接(http://balkanex.info/test/start.html),或者只需查看我下面的代码,然后转到该链接。我必须说我正在制作本地应用程序,因此我无法利用服务器优势。
<!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
跑步者.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
脚本.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');
});
});
}
采纳答案by user3392725
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.
例如,制作字母的图像?然后,在特定字段中,您可以使用此图像更改字母。这是一个相当的工作。因此,我建议您更改库。
回答by Hamzeen Hameem
Please checkout the latest version (v1.4.0) of jsPDF. They just started to support unicode, https://github.com/MrRio/jsPDF/releases/tag/v.1.4.0
请查看jsPDF的最新版本 (v1.4.0)。他们刚刚开始支持 unicode, https://github.com/MrRio/jsPDF/releases/tag/v.1.4.0
回答by liftarn
jsPDF does not support anything outside the ASCII range. See https://github.com/MrRio/jsPDF/issues/12
jsPDF 不支持 ASCII 范围之外的任何内容。见https://github.com/MrRio/jsPDF/issues/12