如何在 iText 7 中创建/设置 table 单元格和边框的自定义颜色?

How to create / set custom color of table cells and borders in iText 7?

我需要创建一个 table,其中包含自定义彩色单元格和边框。 Color class 中定义了几个常量,但我需要自定义颜色。我需要#a6cb0b 作为 header 的背景色和颜色代码为#cccccc 的边框线。我该如何设置它们?

Table table = new Table(new float[]{1,1,1});
Cell cell = new Cell();
cell.add(new Paragraph("TITLE"));
cell.setBackgroundColor(Color.???);
table.addCell(cell);
...
...

了解如何创建颜色的最佳方法是检查 API docs. When you go to the page that describes the 'Color' class,您会看到它有几个子classes:

您似乎想要创建一个 RGB 颜色,因此您需要 DeviceRgb:

Color headerBg = new DeviceRgb(0xA6, 0xCB, 0x0B);
Color lineColor = new DeviceRgb(0xCC, 0xCC, 0xCC);

您可以使用 color 对象来设置边框、背景等的颜色...