如何破解pdf标题中的单词,使用jsPDF生成的PDF

时间:2014-04-14 14:22:30

标签: javascript jquery html jspdf

如何在使用jsPDF生成PDF的同时打破PDF文件中的标题中的单词(即我想将标题分解为&#34; Hello World&#34;分为两行)以及如何在jsPDF中设置字体大小。< / p>

我尝试使用pdf.setFontSize(12);,但它对我不起作用。

任何帮助将不胜感激。感谢。

 var pdf = new jsPDF('l', 'pt', 'a3')   
    , source = $('#TableId')[0] 
    , specialElementHandlers = {

    }

    , margins = {  top: 20, bottom: 20, left: 30, width: 922 };


    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
    )

2 个答案:

答案 0 :(得分:0)

如果您想在两个不同的行上拆分hello和world,请在\nhello之间添加换行符world"hello\nworld"

示例:

var pdf = new jsPDF();
pdf.setFontSize(12);
pdf.text(10, 10, "Hello\nWorld");

或添加两个文本字段:

doc.text(10, 10, "Hello");
doc.text(10, 25, "World");

<强> PS。如果您可以发布所有代码,它会更有帮助。

答案 1 :(得分:0)

如果你使用FromHtml并且你的Text花了多个页面,那么你可以在Text之后添加:   <!-- ADD_PAGE -->

但你应该使用Mrrio libary的Jspdf

链接Download the Jspdf