javascript - 如何将特殊字符导出为 PDF
问题描述
我在使用 jsPDF 将一些特殊字符(塞尔维亚拉丁字母)导出到 PDF 时遇到问题。
我已经应用了转换后的字体并设法使它适用于简单的文本,但是在导出 id="exportContent" 的 div 元素的内容时我无法使它工作。
这是工作并导出带有特殊字符的简单文本的代码:
function demoFontTypes() {
var doc = new jsPDF();
doc.setFont('ARIALUNI'); // set font
doc.setFontSize(10);
doc.text('žsćdšclsdpžcslcpsžclpsdpžclsdžpclsdžclpsć', 10, 10);
doc.save('test.pdf');
}
我正在尝试使用此代码导出 div 元素的内容,但无法导出这些字符(žćđšč)
$(document).ready(function() {
$(".btnPDF").click(function() {
var doc = new jsPDF("p", "pt", "A4");
var source = $("#exportContent")[0];
var margins = {
top: 30,
bottom: 60,
left: 50,
width: 522
};
doc.setFont('ARIALUNI'); // set font
doc.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, {
// y coord
width: margins.width // max width of content on PDF
},
function(dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
doc.save("Test.pdf");
},
margins
);
});
});
我需要能够使用特殊字符(塞尔维亚拉丁语)导出 div 元素的内容
解决方案
推荐阅读
- reactjs - 材质ui时间选择器应该传递什么格式?
- javascript - 将样式转移图像应用于圆形蒙版 P5.js
- android - RecyclerView 在滚动时覆盖 ImageView
- node.js - 瓶颈库作业停止执行
- python - 如何使用 pandas 使用列名检查 CSV 中的重复名称、mac 地址和 mac 地址长度
- oracle - 对链接数据库执行查询时,在本地 Oracle 数据库上使用了哪些资源?
- python - Python multiprocessing manger.list() 未正确传递给 Matplotlib.animation
- openssl - ssl_crtd 助手崩溃太快,需要帮助!鱿鱼3.5
- javascript - 事件循环、Promise 和 setTimeout
- apache-spark - 从 hdfs 导入嵌套目录数据集