How to change the font color with canvas

1

I draw a string at the X, Y coordinates

pdf.drawString(230, 780, u"Contrato de CubanCloud")

Now I want that instead of leaving that chain in black, I want it to come out blue, please tell me how I can do it.

    
asked by Roberto Cárdenas 08.05.2017 в 17:18
source

2 answers

1

Because of the code you share, it seems that you are generating a PDF using canvas in ReportLab. So to change the color, the first thing you should do is define what color you want to use with the setFillColor method before calling drawString .

For example, if you want it to be blue instead of black, you would do something like this:

pdf.setFillColor(blue)
pdf.drawString(230, 780, u"Contrato de CubanCloud")

You could also use setFillColorRGB to indicate the color in RGB mode by passing 3 parameters. You can find more information in the ReportLabs documentation on colors .

    
answered by 09.06.2017 / 13:31
source
1

In basic JavaScript this is done:

var papel = document.getElementById("papel");
var lapiz = papel.getContext("2d");

lapiz.font = '30px Verdana';
lapiz.fillStyle = 'blue';
lapiz.fillText('Esto es azul', 10, 40);

lapiz.fillStyle = 'red';
lapiz.fillText('Esto es rojo', 20, 80);

lapiz.fillStyle = 'yellow';
lapiz.strokeStyle = "black";
lapiz.fillText('Esto es amarillo con borde negro', 10, 120);
lapiz.strokeText('Esto es amarillo con borde negro', 10, 120);
<canvas id="papel" width="600" height="200">
</canvas>
    
answered by 17.05.2017 в 04:28