Yevhenii Bahmutskyi
Yevhenii Bahmutskyi

Reputation: 1661

How to change line color in jspdf?

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

Upvotes: 3

Views: 15916

Answers (3)

manimk
manimk

Reputation: 54

You have to call the setDrawColor function from the jsPDF. This example definitely helps you

var pdf = new jsPDF();
pdf.setDrawColor("#096dd9");

//horizontal line
pdf.setLineWidth(0.2)
pdf.line(2, 25, 555, 25);

//vertical line
pdf.line(30, 2, 30, 100);

Upvotes: 0

Yevhenii Bahmutskyi
Yevhenii Bahmutskyi

Reputation: 1661

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.

Upvotes: 18

Grimalt Santiago
Grimalt Santiago

Reputation: 141

You must call the setDrawColor function before the line function. For example:

var doc = new jsPDF();
doc.setDrawColor(255,0,0);  // draw red lines
doc.line(100, 20, 100, 60);
doc.save('Red_line.pdf');

Upvotes: 2

Related Questions