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

余生长醉 提交于 2020-07-06 20:23:32

问题


I need to create a table which has custom colored cells and borders. There are a few constants defined in the Color class, but what I need a custom color. I need #a6cb0b as the background color for the header and border lines with color code #cccccc. How do I set them?

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

回答1:


The best way to find out how to create colors, is to check the API docs. When you go to the page that describes the 'Color' class, you see that it has several subclasses:

  • DeviceGray
  • DeviceRgb
  • DeviceCmyk
  • ...

It seems that you want to create an RGB color, hence you need DeviceRgb:

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

You can use the color object to set the color of borders, backgrounds, etc...



来源:https://stackoverflow.com/questions/47038011/how-to-create-set-custom-color-of-table-cells-and-borders-in-itext-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!