我想在itext下面的表格中为背景颜色提供背景颜色如何完成? [英] i want to give background color to top of the row for following table in itext how it can be done?

查看:393
本文介绍了我想在itext下面的表格中为背景颜色提供背景颜色如何完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try
	 {
		 BufferedReader  br = new BufferedReader(new FileReader(fname));
		 no=br.readLine();
		 String[] num=no.split(",");
		 int n=num.length;
		 PdfPTable table = new PdfPTable(n);
		 table.setWidthPercentage(100);

		 BufferedReader  br1 = new BufferedReader(new FileReader(fname));
		 while ((line = br1.readLine()) != null)
		 {
			
			String line1=line;
			 String[] parts = line1.split(",");
			 for(int i=0;i<parts.length;i++)>
			 {
			  part2 = parts[i]; 
			  PdfPCell cell1 = new PdfPCell(new Paragraph(part2));
			 
			
			  
			  table.addCell(cell1);
			 }
			 
			 addEmptyLine(preface1, 1);
			
		 }
		

		 document.add(table); 
	 }
	 catch(IOException e)
	 {
		  e.printStackTrace();   

	 }

推荐答案

你可以通过修改字体来做到这一点:



You can do that by modifiying the font:

Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12);
f1.setColor(BaseColor.BLUE);
cell.addfont(f1); 





请检查应用字体的位置,以便更改正确数量的文本。

此外它之后可能需要更改回黑色字体(如果不是某个图层的所有元素都应该更改)。



Please check where to apply the font so that the right amount of text is changed.
Also it might be needed to change back to black font afterwards (if not all elements of a certain layer are supposed to change).


这篇关于我想在itext下面的表格中为背景颜色提供背景颜色如何完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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