Hi Brain,
Thank you for contacting Syncfusion support,
We have analyzed your requirements and the given code snippet, currently we do not have support for binding the cell style values from the BeginCellEvent. We can achieve different text color for each column by using the BeginCellEvent. Please find the below code snippet to draw the alternative text color for alternative column.
Code snippet:
//BeginCell Event metod.
private void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
{
//Check the even cells.
if (args.CellIndex % 2 == 0)
{
//Draw the alternative table cell with the alternative color.
args.Graphics.DrawString(args.Value, font, PdfPens.Red, args.Bounds);
args.Skip = true;
}
} |
Please let us know if you need further assistance.
Regards.
Sasi Kumar S.
Dear Sir,
Thank you for your help, but I can't lose the back color text what ever I try.
Could I ask for your assistane again?
This is what I have.
What I have tried:
Lose the text color in both the styles.
Force some silly color in the extra functie BeginCellLayoutEventHandler
with brush and with pen.
But the column text is still in black.
Here is what I have now:
public void AanmakenPDF()
{
try
{
FoutOmschrijving = "";
PdfLoadedDocument doc = new PdfLoadedDocument(_BeginBestand);
//Get first page from document
PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage;
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
PdfFont fontAdres = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Draw the text.
graphics.DrawString(Debiteur.ADRES, fontAdres, PdfBrushes.Black, new PointF(10, 120));
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
//Draw the text.
graphics.DrawString(_AutodocForm, font, PdfBrushes.White, new PointF(250, 120));
graphics.DrawString(Debiteur.EMAIL, font, PdfBrushes.White, new PointF(250, 140));
graphics.DrawString(Debiteur.NAAM, font, PdfBrushes.WhiteSmoke, new PointF(250, 160));
// Create a PdfLightTable.
PdfLightTable pdfLightTable = new PdfLightTable();
//Assign data source.
DataTable AndereVolgorde = new DataTable();
AndereVolgorde.Columns.Add("NR");
AndereVolgorde.Columns.Add("OMSCHRIJVING");
AndereVolgorde.Columns.Add("LINK");
foreach (DataRow rij in Table.Rows)
{
DataRow _rij = AndereVolgorde.NewRow();
_rij["NR"] = rij["TOELATINGSNR"];
_rij["OMSCHRIJVING"] = rij["OMSCHRIJVING"];
_rij["LINK"] = rij["LINK"];
AndereVolgorde.Rows.Add(_rij);
}
pdfLightTable.DataSource = AndereVolgorde;
#region Cell Styles
//Create Pdf pen for drawing broder
PdfPen borderPen = new PdfPen(PdfBrushes.DarkBlue);
borderPen.Width = 0;
PdfColor zwart = new PdfColor(33, 67, 126);
PdfSolidBrush zwarte_brush = new PdfSolidBrush(zwart);
PdfPen TekstPen = new PdfPen(zwart);
//Create cell styles
PdfCellStyle altStyle = new PdfCellStyle();
altStyle.Font = font;
altStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(192, 201, 219));
altStyle.BorderPen = borderPen;
//altStyle.TextBrush = zwarte_brush;
//altStyle.TextPen = TekstPen;
altStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
PdfCellStyle defStyle = new PdfCellStyle();
defStyle.Font = font;
defStyle.BackgroundBrush = PdfBrushes.White;
defStyle.BorderPen = borderPen;
//defStyle.TextBrush = zwarte_brush;
//defStyle.TextPen = TekstPen;
defStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
PdfCellStyle headerStyle = new PdfCellStyle(font, PdfBrushes.White, PdfPens.DarkBlue);
headerStyle.BackgroundBrush = new PdfSolidBrush(Color.FromArgb(33, 67, 126));
headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
#endregion
#region Format Table
//Set table alternate row style
pdfLightTable.Style.AlternateStyle = altStyle;
//Set default style
pdfLightTable.Style.DefaultStyle = defStyle;
//Set header row style
pdfLightTable.Style.HeaderStyle = headerStyle;
//Show the header row
pdfLightTable.Style.ShowHeader = true;
//Repeate header in all the pages
pdfLightTable.Style.RepeatHeader = true;
//Set header data from column caption
pdfLightTable.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
pdfLightTable.Style.BorderPen = borderPen;
pdfLightTable.Style.CellPadding = 2;
pdfLightTable.Columns[0].Width = 2;
pdfLightTable.Columns[1].Width = 8;
#endregion
pdfLightTable.BeginCellLayout += new BeginCellLayoutEventHandler(pdfLightTable_BeginCellLayout);
//Draw PdfLightTable.
pdfLightTable.Draw(graphics, new PointF(10, 200));
//Save the document.
doc.Save(_EindBestand);
//Close the document
doc.Close(true);
}
catch (System.Exception ex)
{
FoutOmschrijving = "Er is een fout opgetreden in de functie AanmakenPDF()." + System.Environment.NewLine + ex.Message;
//Debug.Print(ex.Message);
}
}
private void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
{
float x = args.Bounds.X;
float y = args.Bounds.Y;
float width = args.Bounds.Right;
float height = args.Bounds.Bottom;
try
{
if (args.Value.Contains("http"))
{
PdfTextWebLink textLink = new PdfTextWebLink();
textLink.Url = args.Value;
textLink.Text = args.Value;
textLink.Brush = PdfBrushes.Black;
textLink.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
textLink.DrawTextWebLink(args.Graphics, new PointF(x, y));
args.Skip = true;
}
if (args.CellIndex == 0)
{
PdfColor zwart = new PdfColor(10, 10, 0);
PdfPen zwarte_pen = new PdfPen(zwart);
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
args.Graphics.DrawString(args.Value, font, zwarte_pen, args.Bounds);
}
if (args.CellIndex == 1)
{
PdfColor Bijna_zwart = new PdfColor(33, 67, 126);
PdfPen Bijna_zwarte_pen = new PdfPen(Bijna_zwart);
PdfSolidBrush kleur = new PdfSolidBrush(Bijna_zwart);
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
args.Graphics.DrawString(args.Value, font, kleur, args.Bounds);
}
if (args.CellIndex == 2)
{
PdfColor Geen_zwart = new PdfColor(30, 30, 2);
PdfPen Geen_zwarte_pen = new PdfPen(Geen_zwart);
PdfSolidBrush kleur = new PdfSolidBrush(Geen_zwart);
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
args.Graphics.DrawString(args.Value, font, kleur, args.Bounds);
}
}
catch (System.Exception ex)
{
FoutOmschrijving = "Er is een fout opgetreden in de functie pdfLightTable_BeginCellLayout()." + System.Environment.NewLine + ex.Message;
// Debug.Print(ex.Message);
}
}
Thanks in advance.
Brian