java 如何在itext中设置自定义颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11385291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set a custom color in itext?
提问by Dragan
Thanks for taking the time to answer my question.
感谢您抽出时间回答我的问题。
I'm generating a PDF document using iText in Java. I need to set the column headers of a table a different colour than the ones in the values columns. I have the color hexadecimal value from Photoshop. I'm using PdfPTable with chunks and paragraphs. how do I set them to a different colour, other than the ones predefined in the BaseColor enum?
我正在使用 Java 中的 iText 生成 PDF 文档。我需要将表格的列标题设置为与值列中的颜色不同的颜色。我有来自 Photoshop 的颜色十六进制值。我正在将 PdfPTable 与块和段落一起使用。除了 BaseColor 枚举中预定义的颜色之外,如何将它们设置为不同的颜色?
Thanks in advance!
提前致谢!
回答by Mark
You'll need to take your 8-bit hexadecimal color value and convert it to 8-bit RGB values.
您需要将 8 位十六进制颜色值转换为 8 位 RGB 值。
How to convert hex to rgb using Java?
Then you'll be able to create a new BaseColorwith your RGB values.
然后您将能够使用您的 RGB 值创建一个新的BaseColor。
cell.setBackgroundColor(new BaseColor(255, 0, 0));