使用 .fromHTML 方法生成 PDF 时文本对齐方式不正确

Text alignment not appearing properly when generated PDF using .fromHTML method

我创建了 JavaScript 代码以从 HTML 后端获取数据并将该 HTML 转换为 PDF。

生成PDF,我用的是JSPDF。

我的 HTML 字符串如下所示:

"<p><span style="font-family:calibri;font-size:17.3333px;">Dear [@Client Name],<br></span></p><p><span style="font-family:calibri;font-size:17.3333px;">This is a sample letter that I need filled out for [@Client Name 2], who lives in [@City],[@Province]. On this date, the [@Number Date], of ​[@Month],[@Year]. It occurred to me that [@Client Name] was talking to [@Client Name 3].<br></span></p><p><span style="font-family:calibri;font-size:17.3333px;">The end.</span></p><p><span style="font-family:calibri;font-size:17.3333px;">Appriciate your time.<br></span></p><p><span style="font-family:calibri;font-size:17.3333px;">[@Date]</span><br></p>"

使用 JSPDF 生成的 PDF 如下所示:

生成HTML的代码是:

    function GeneratePDF(content) { 


        var doc = new jsPDF();  
        var specialElementHandlers = {
            '#editor': function (element, renderer) {
                return true;
            }
        };

        doc.fromHTML(content, 15, 15, {
            'width': 250,
                'elementHandlers': specialElementHandlers
        });
        doc.save('sample-file.pdf');
}

能否请您指导我如何管理对齐以管理内容。另外,如何管理字体以及如何删除 þÿ 字符?

请检查 http://jsfiddle.net/2rhsvgkk/

灵感来自 How to properly use jsPDF library

HTML

<div id="customers">
   <p>Dear [@Client Name],</p>
   <p>This is a sample letter that I need filled out for [@Client Name 2], who lives in [@City], [@Province].  On this date, the [@Number Date], of [@Month],[@Year]. It occurred to me that [@Client Name] was talking to [@Client Name 3].</p>
   <p>The end.</p>
   <p>Appriciate your time.</p>
   <p>[@Date]</p>
</div>
<button onclick="javascript:demoFromHTML();">PDF</button>

您正在使用一些不必要的 <span><br> 标签。

希望对您有所帮助