Boris_56
Boris_56

Reputation: 47

How to set the color in IText via rgb?

Is it possible to set the color in IText via rgb?
I set the color this way:

canvas.SetFillColor(ColorConstants.BLUE);

I would like to set the color more accurately.

Upvotes: 2

Views: 3654

Answers (3)

Andrew
Andrew

Reputation: 2675

For iText7:

    com.itextpdf.kernel.color.Color colorBlue = new DeviceRgb(0, 0, 255);
    canvas.SetFillColor(colorBlue);

see Kernal.Colors for more information, there are numerous options there.

For iText5: You should be able to create a new BaseColor e.g.

canvas.SetFillColor(new BaseColor(0,0,255));

BaseColor doc

Upvotes: 4

Boris_56
Boris_56

Reputation: 47

I understood. I need to set color for PdfLinkAnnotation using RGB. This is done like this:

PdfLinkAnnotation annotation = new PdfLinkAnnotation(rect);

annotation.SetColor(new PdfArray(new float[] { 0.5647f, 0.9334f, 0.5647f }));

Upvotes: 0

Alexey S. Larionov
Alexey S. Larionov

Reputation: 7937

From the IText API documentation: you could use SetFillColorRgb:

virtual iText.Kernel.Pdf.Canvas.PdfCanvas iText.Kernel.Pdf.Canvas.PdfCanvas.SetFillColorRgb(float r, float g, float b)

Upvotes: -1

Related Questions