设计应用程序时出现字体颜色问题

时间:2019-04-12 05:58:32

标签: c#

在创建pdf文本写入,获取字体大小,颜色并存储在属性中时,我在c#中的字体颜色设计中遇到问题。在这里,我需要编写功能并知道如何传递颜色作为输入变量以获取输出。如果我写了有关创建pdf和字体输入参数的kavin,它应该根据给定的字体大小标签和颜色来表现。

Document doc = new Document(PageSize.LETTER, Convert.ToInt32(properties.PageLeft), Convert.ToInt32(properties.PageRight), Convert.ToInt32(properties.PageTop), Convert.ToInt32(properties.PageBottom) );
PdfWriter write = PdfWriter.GetInstance(doc, new FileStream(properties.PdfPath, FileMode.Create)); 
doc.Open(); 
Font font = FontFactory.GetFont(properties.Font, Convert.ToInt32(properties.FontSize)); 
Paragraph paragraph = new Paragraph(properties.Text); 
doc.Add(paragraph); 
doc.Close(); //This is the code except color 

1 个答案:

答案 0 :(得分:0)

嗨,kavin将来尝试添加您正在使用的库,这完全适合我们。

在您的代码上下文中,我相信您正在使用IText。

我认为您也不会共享变量列表,这使事情变得复杂。


Document doc = new Document(PageSize.LETTER, Convert.ToInt32(properties.PageLeft), Convert.ToInt32(properties.PageRight), Convert.ToInt32(properties.PageTop), Convert.ToInt32(properties.PageBottom) );
PdfWriter write = PdfWriter.GetInstance(doc, new FileStream(properties.PdfPath, FileMode.Create)); 
doc.Open(); 
Font font = FontFactory.GetFont("What font you want", "Font size" , "Color.RED"); 
Paragraph paragraph = new Paragraph(properties.Text); 
doc.Add(paragraph); 
doc.Close(); //This is the code except color 


Font font = FontFactory.GetFont("Arial", "28" , Color.RED); //A more specific Example

//If this doesnt work try and use:

paragraph.setColorFill(BaseColor.RED);


请告诉我这是否无效,并且我会尽力为您提供进一步的帮助。

相关问题