简体   繁体   English

如何在pdf标头中打断单词,使用jsPDF生成的PDF

[英]How to break word in pdf header, PDF generated using jsPDF

How to break words in Headers in PDF file, while generating PDF using jsPDF(ie I want to break the headers like "Hello World" into two lines) and how to set font size in jsPDF. 如何使用jsPDF生成PDF时,如何在PDF文件的标题中拆分单词(即,我想将“ Hello World”之类的标题拆分为两行),以及如何在jsPDF中设置字体大小。

I have tried with pdf.setFontSize(12); 我已经尝试使用pdf.setFontSize(12); , but it does not work for me. ,但对我不起作用。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

code: 码:

 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
    )

If you want to split hello and world on two different lines, add a newline \\n between hello and world : "hello\\nworld" 如果要在两个不同的行上拆分hello和world,请在helloworld之间添加换行符\\n"hello\\nworld"

Example: 例:

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

Or add two text fields: 或添加两个文本字段:

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

ps. ps。 It would even more help if you could post all your code. 如果您可以发布所有代码,则将提供更多帮助。

If You use FromHtml and your Text spent more than one Page, so you can add after the Text : <!-- ADD_PAGE --> 如果您使用FromHtml并且您的文本花费了多个页面,则可以在文本之后添加: <!-- ADD_PAGE -->

But you should use the Jspdf from Mrrio libary 但是您应该使用Mrrio libary的Jspdf

Link : Download the Jspdf 链接下载Jspdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM