jsPDF can't get any styling to work

后端 未结 4 796
迷失自我
迷失自我 2020-11-27 05:17

I\'m new to using jsPDF but and for the life of me I can\'t get any css to apply to this thing! I\'ve tried inline, internal, and external all to no avail! I read in another

4条回答
  •  失恋的感觉
    2020-11-27 06:18

    I think the problem is that you use media="print" instead of media="screen". Try making two seperate files, one for print and one for the screen:

    
    
    

    The screen one will contain the styling for the page as seen in a browser. The print one will contain the styling for when you print your page, or in this case saving it as a PDF.

    EDIT

    I checked the jsPDF website but I think they don't support CSS. You could do something like this to create a document with different text colors though:

    doc.setFontSize(22);
    doc.setTextColor(255, 0, 0);
    doc.text(20, 20, 'This is a title');
    
    doc.setFontSize(16);
    doc.setTextColor(0, 255, 0);
    doc.text(20, 30, 'This is some normal sized text underneath.');
    

    Put this code right under var doc = new jsPDF('landscape'); in your script.

提交回复
热议问题