Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a custom color in itext?

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!

like image 645
Dragan Avatar asked Jul 08 '12 17:07

Dragan


1 Answers

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));
like image 88
Mark Avatar answered Sep 21 '22 15:09

Mark