Hi,
Is it possible to style header row in the PDF file when a datatable is exported Just like we can do in XLS file? I want to have a background color and custom font color in the table header in PDF?
Thanks in advance
PdfDocument doc = new PdfDocument();
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
float y = 10;
PdfTable table = new PdfTable();
table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.LightBlue;
table.Style.ShowHeader = true;
using (OleDbConnection conn = new OleDbConnection())
{
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\demo.mdb";
OleDbCommand command = new OleDbCommand();
command.CommandText
= " select Name,Capital,Continent,Area,Population from country ";
command.Connection = conn;
using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
{
DataTable dataTable = new DataTable();
dataAdapter.Fill(dataTable);
table.DataSourceType = PdfTableDataSourceType.TableDirect;
table.DataSource = dataTable;
}
}
PdfLayoutResult result = table.Draw(page, new PointF(0, y));
doc.SaveToFile("SimpleTable.pdf");
DataTable dataTable;
using (OleDbConnection conn = new OleDbConnection())
{
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\demo.mdb";
OleDbCommand command = new OleDbCommand();
command.CommandText
= " select Name,Capital,Continent,Area,Population from country ";
command.Connection = conn;
using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
{
dataTable = new DataTable();
dataAdapter.Fill(dataTable);
}
}
Spire.DataExport.HTML.HTMLExport HTMLExport = new Spire.DataExport.HTML.HTMLExport();
Spire.DataExport.PDF.PDFExport PDFExport = new Spire.DataExport.PDF.PDFExport();
PDFExport.PDFOptions.TitleFont.Color = Color.Red;
PDFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
PDFExport.DataTable = dataTable;
PDFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
PDFExport.SaveToFile("20110223.pdf");