简体   繁体   English

如何在 itext 中设置自定义颜色?

[英]How to set a custom color in itext?

Thanks for taking the time to answer my question.感谢您抽出时间回答我的问题。

I'm generating a PDF document using iText in Java.我在 Java 中使用 iText 生成 PDF 文档。 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.我有来自 Photoshop 的颜色十六进制值。 I'm using PdfPTable with chunks and paragraphs.我正在使用带有块和段落的 PdfPTable。 how do I set them to a different colour, other than the ones predefined in the BaseColor enum?除了 BaseColor 枚举中预定义的颜色之外,如何将它们设置为不同的颜色?

Thanks in advance!提前致谢!

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 BaseColor with your RGB values.然后您将能够使用您的 RGB 值创建一个新的BaseColor

cell.setBackgroundColor(new BaseColor(255, 0, 0));
Cell hcell = new Cell();   
Color color = WebColors.getRGBColor("red");
hcell.setBackgroundColor(color);

Take a look at this site .看看这个网站 Even though it says C# there are only Java codes.即使它说 C# 也只有 Java 代码。 Let me know if you find it or not.如果你找到了,请告诉我。 I created an successful PDF system looking at those examples.我通过查看这些示例创建了一个成功的 PDF 系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM