尝试使用希伯来语字符从 html 导出 PDF



我正在尝试将表格导出为 PDF 文件,但如果有希伯来语字符,它将无法正确显示它们。

我尝试在 HEAD 部分添加 UTF-8 的 mata 标签,以及 php 标头的 'Content-Type: text/html; charset=utf-8'

function demoFromHTML() {
    var pdf = new jsPDF('p', 'pt', 'letter');
    source = $('#customers')[0];
    specialElementHandlers = {
        // element with id of "bypass" - jQuery style selector
        '#bypassme': function (element, renderer) {
            // true = "handled elsewhere, bypass text extraction"
            return true
        }
    };
    margins = {
        top: 80,
        bottom: 60,
        left: 10,
        width: 300
    };
    pdf.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
        'elementHandlers': specialElementHandlers
    },
    function (dispose) {
        pdf.save('Test.pdf');
    }, margins);
}

您正在将特定元素的 HTML 导出到 PDF 文件,此 HTML 不包含任何标题信息,因此您应该在将其导出为 pdf 之前添加此信息。在这里,您可以看到如何添加 utf-8 信息的示例。

pdf.fromHTML(
    '<html><head><meta charset="utf-8" /><body>' + source + '</body></html',
    margins.left, // x coord
    margins.top, { // y coord
        'width': margins.width, // max width of content on PDF
        'elementHandlers': specialElementHandlers
    }
    ...
);

我认为您可以使用dir="rtl"了解更多信息,请通过以下链接

https://developers.itextpdf.com/ja/node/2079

最新更新