How to set a custom color in itext?
Asked Answered
E

3

11

Thanks for taking the time to answer my question.

I'm generating a PDF document using iText in Java. I need to set the column headers of a table a different colour than the ones in the values columns. I have the color hexadecimal value from Photoshop. I'm using PdfPTable with chunks and paragraphs. how do I set them to a different colour, other than the ones predefined in the BaseColor enum?

Thanks in advance!

Egan answered 8/7, 2012 at 17:48 Comment(1)
@DavidKroukamp thanks for the reply, I have come across this link. However the example is making use of the predefined colors in the BaseColor enum which is not what I am after...Egan
R
23

You'll need to take your 8-bit hexadecimal color value and convert it to 8-bit RGB values.

How to convert hex to rgb using Java?

Then you'll be able to create a new BaseColor with your RGB values.

cell.setBackgroundColor(new BaseColor(255, 0, 0));
Romaic answered 17/1, 2013 at 14:55 Comment(0)
F
1
Cell hcell = new Cell();   
Color color = WebColors.getRGBColor("red");
hcell.setBackgroundColor(color);
Fabiano answered 9/10, 2020 at 9:19 Comment(0)
C
-5

Take a look at this site. Even though it says C# there are only Java codes. Let me know if you find it or not. I created an successful PDF system looking at those examples.

Cutlet answered 10/7, 2012 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.