如何在iText 7中创建/设置表格单元格和边框的自定义颜色? [英] How to create / set custom color of table cells and borders in iText 7?

查看:739
本文介绍了如何在iText 7中创建/设置表格单元格和边框的自定义颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个具有自定义彩色单元格和边框的表格.在Color类中定义了一些常量,但是我需要自定义颜色.我需要使用#a6cb0b作为颜色代码为#cccccc的标题行和边框行的背景色.我该如何设置?

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);
...
...

推荐答案

了解如何创建颜色的最佳方法是检查'颜色'类,您会看到它具有几个子类:

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
  • ...

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

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);

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

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

这篇关于如何在iText 7中创建/设置表格单元格和边框的自定义颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆