我正在努力使用jspdf 库将 html 页面导出为 pdf 文件,但没有成功。这里有一个类似的问题,但答案不好。问题出在 UTF-8 字符中,即使我将所有文档都设为 utf8。我应该怎么做才能使这个库(parall.ax/products/jspdf)将诸如š,č,ć之类的字母插入pdf?
这是您可以尝试此问题的链接(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>
亚军.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>');
}
脚本.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');
});
});
}