[英]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.我在 Java 中使用 iText 生成 PDF 文档。 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.
我有来自 Photoshop 的颜色十六进制值。 I'm using PdfPTable with chunks and paragraphs.
我正在使用带有块和段落的 PdfPTable。 how do I set them to a different colour, other than the ones predefined in the BaseColor enum?
除了 BaseColor 枚举中预定义的颜色之外,如何将它们设置为不同的颜色?
Thanks in advance!提前致谢!
You'll need to take your 8-bit hexadecimal color value and convert it to 8-bit RGB values.您需要获取 8 位十六进制颜色值并将其转换为 8 位 RGB 值。
How to convert hex to rgb using Java? 如何使用 Java 将十六进制转换为 rgb?
Then you'll be able to create a new BaseColor with your RGB values.然后您将能够使用您的 RGB 值创建一个新的BaseColor 。
cell.setBackgroundColor(new BaseColor(255, 0, 0));
Cell hcell = new Cell();
Color color = WebColors.getRGBColor("red");
hcell.setBackgroundColor(color);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.