【问题标题】:Trying to export PDF from html with hebrew charactars尝试使用希伯来语字符从 html 导出 PDF
【发布时间】:2018-12-24 11:23:59
【问题描述】:

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

我尝试在 HEAD 部分添加 UTF-8 的 mata 标记以及 'Content-Type: text/html; 的 php 标头;字符集=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);
}

【问题讨论】:

    标签: javascript html


    【解决方案1】:

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

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

    【讨论】:

    • 问题在于希伯来语变成:“é Þ è Ù ê Õ Ù Õ à Ù á Ñ Ò ( 4 )”
    【解决方案2】:

    您正在将特定元素的 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
        }
        ...
    );
    

    【讨论】:

    • 不工作... PDF 显示:“[object HTMLDivElement]”
    猜你喜欢
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多