在Pdf中更改Datagrid标题颜色 [英] Changing the Datagrid Header Colour in Pdf
本文介绍了在Pdf中更改Datagrid标题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理导出到Pdf进程。使用ITextSharp dll我创建但是当我打开Pdf标题时颜色没有改变。
问候
Balamurugan
Hi,
I'm working on Export to Pdf process.Using ITextSharp dll i have created but when i opened Pdf header color is not changed.
Regards
Balamurugan
推荐答案
Atlast i itslef解决了问题... :) :) :) br />
Atlast i itslef solved the Problem...:) :) :)
private void button1_Click(object sender, RoutedEventArgs e)
{
ExportPdf(pdftbl);
}
public void ExportPdf(DataTable dt)
{
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C://Bala//testpdf.pdf", FileMode.Create));
document.Open();
iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5);
PdfPTable table = new PdfPTable(dt.Columns.Count);
PdfPRow row = null;
float[] widths = new float[] { 4f, 4f, 4f };
//Creating Header Color Change
PdfPCell CellActext = new PdfPCell(new Phrase(new Chunk("Name", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.GREEN))));
CellActext.Colspan = 1;
CellActext.Border = 0;
CellActext.HorizontalAlignment = Element.ALIGN_LEFT;
CellActext.BackgroundColor = new iTextSharp.text.Color(24, 150, 191);
table.AddCell(CellActext);
PdfPCell CellActext1 = new PdfPCell(new Phrase(new Chunk("Age", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.ORANGE))));
CellActext1.Colspan = 1;
CellActext1.Border = 0;
CellActext1.HorizontalAlignment = Element.ALIGN_LEFT;
CellActext1.BackgroundColor = new iTextSharp.text.Color(25, 140, 181);
table.AddCell(CellActext1);
PdfPCell CellActext2 = new PdfPCell(new Phrase(new Chunk("SecondName", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLUE))));
CellActext2.Colspan = 1;
CellActext2.Border = 0;
CellActext2.HorizontalAlignment = Element.ALIGN_LEFT;
CellActext2.BackgroundColor = new iTextSharp.text.Color(23, 130, 111);
table.AddCell(CellActext2);
table.SetWidths(widths);
table.WidthPercentage = 100;
int iCol = 0;
string colname = "";
foreach (DataColumn c in dt.Columns)
{
table.AddCell(new Phrase(c.ColumnName, font5));
}
foreach (DataRow r in dt.Rows)
{
if (dt.Rows.Count > 0)
{
table.AddCell(new Phrase(r[0].ToString(), font5));
table.AddCell(new Phrase(r[1].ToString(), font5));
table.AddCell(new Phrase(r[2].ToString(), font5));
}
}
document.Add(table);
document.Close();
}
这篇关于在Pdf中更改Datagrid标题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文