Click here to Skip to main content
16,012,107 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

Atlast i itslef solved the Problem...:) :) :)
C#
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();
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900