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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:52:24  来源:igfitidea点击:

How to set a custom color in itext?

javauitextfielditext

提问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?

如何使用 Java 将十六进制转换为 rgb?

Then you'll be able to create a new BaseColorwith your RGB values.

然后您将能够使用您的 RGB 值创建一个新的BaseColor

cell.setBackgroundColor(new BaseColor(255, 0, 0));

回答by Navin

Take a look at this site. Even though it says C# there are only Java codes. Let me know if you find it or not. I created an successful PDF system looking at those examples.

看看这个网站。即使它说 C# 也只有 Java 代码。如果你找到了,请告诉我。我通过查看这些示例创建了一个成功的 PDF 系统。