Search code examples
javascriptjspdf

How to change line color in jspdf?


How to change the color of line, produced by using line(x1, y1, x2, y2) method?


Solution

  • Looks like it is possible to accomplish this using setDrawColor() function.

    var doc = new jsPDF();
    doc.setDrawColor(255, 0, 0);
    doc.line(35, 30, 100, 30);
    
    doc.save('line.pdf'); 
    

    JSFiddle

    UPD: if you add new page to document, you need to run setDrawColor() function again. Otherwise the color on the new page will be default black.