简体   繁体   中英

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.

I have tried with 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"

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. 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 -->

But you should use the Jspdf from Mrrio libary

Link : Download the Jspdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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