我需要创建一个具有自定义颜色单元格和边框的表格。里面定义了几个常量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);
...
...
了解如何创建颜色的最佳方法是检查API docs http://itextsupport.com/apidocs/iText7/latest/。当您转到描述该内容的页面时'Color' http://itextsupport.com/apidocs/iText7/latest/com/itextpdf/kernel/color/Color.html类,你会看到它有几个子类:
- 设备格雷 http://itextsupport.com/apidocs/iText7/latest/com/itextpdf/kernel/color/DeviceGray.html
- 设备RGB http://itextsupport.com/apidocs/iText7/latest/com/itextpdf/kernel/color/DeviceRgb.html
- 设备Cmyk http://itextsupport.com/apidocs/iText7/latest/com/itextpdf/kernel/color/DeviceCmyk.html
- ...
看来你想创建一个 RGB 颜色,因此你需要DeviceRgb
:
Color headerBg = new DeviceRgb(0xA6, 0xCB, 0x0B);
Color lineColor = new DeviceRgb(0xCC, 0xCC, 0xCC);
您可以使用color
对象设置边框、背景等的颜色...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)