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

nit*_*ppa 3 java pdf itext7

我需要创建一个具有自定义彩色单元格和边框的表格。Color类中定义了一些常量,但我需要自定义颜色。我需要#a6cb0b 作为带有颜色代码#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);
...
...
Run Code Online (Sandbox Code Playgroud)

Bru*_*gie 5

了解如何创建颜色的最佳方法是查看API 文档。当您转到描述'Color'类的页面时,您会看到它有几个子类:

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

Color headerBg = new DeviceRgb(0xA6, 0xCB, 0x0B);
Color lineColor = new DeviceRgb(0xCC, 0xCC, 0xCC);
Run Code Online (Sandbox Code Playgroud)

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