Dear Sir,
I keep having problems with the link.
If I use the table lay-out code:
#region Cell Styles
//Create Pdf pen for drawing broder
PdfPen borderPen = new PdfPen(PdfBrushes.DarkBlue);
borderPen.Width = 0;
//Create cell styles
PdfCellStyle altStyle = new PdfCellStyle();
altStyle.Font = font;
altStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(192, 201, 219));
altStyle.BorderPen = borderPen;
PdfCellStyle defStyle = new PdfCellStyle();
defStyle.Font = font;
defStyle.BackgroundBrush = PdfBrushes.White;
defStyle.BorderPen = borderPen;
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[1].Width = 12;
#endregion
And then your code,
pdfLightTable.BeginCellLayout += new BeginCellLayoutEventHandler(pdfLightTable_BeginCellLayout); the text doesn't become a link.
But if I comment the cell and table lay-out code the link get printed in the table but with a strange lay-out.
Is it possible to have both?
A clean table and a cell with a link?
Thank you in advance.
Brian
PS This is the complete code I am using:
#region Methods
public void AanmakenPDF()
{
try
{
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 fontDJ = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
string DearJohn = "Beste " + Debiteur.PERSOON;
//Draw the text.
graphics.DrawString(DearJohn, fontDJ, PdfBrushes.Black, new PointF(10, 180));
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
string Body = "Sinds " + _BeginDatum + " heeft U de volgende artikelen gekocht:";
//Draw the text.
graphics.DrawString(Body, font, PdfBrushes.Black, new PointF(20, 200));
//Draw the text.
graphics.DrawString(_AutodocForm, font, PdfBrushes.White, new PointF(1, 1));
graphics.DrawString(Debiteur.EMAIL, font, PdfBrushes.White, new PointF(1, 10));
graphics.DrawString(Debiteur.NAAM, font, PdfBrushes.WhiteSmoke, new PointF(1, 20));
// Create a PdfLightTable.
PdfLightTable pdfLightTable = new PdfLightTable();
//Assign data source.
DataTable AndereVolgorde = new DataTable();
AndereVolgorde.Columns.Add("TOELATINGSNR");
AndereVolgorde.Columns.Add("OMSCHRIJVING");
AndereVolgorde.Columns.Add("LINK");
foreach (DataRow rij in Table.Rows)
{
DataRow _rij = AndereVolgorde.NewRow();
_rij["TOELATINGSNR"] = 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;
//Create cell styles
PdfCellStyle altStyle = new PdfCellStyle();
altStyle.Font = font;
altStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(192, 201, 219));
altStyle.BorderPen = borderPen;
PdfCellStyle defStyle = new PdfCellStyle();
defStyle.Font = font;
defStyle.BackgroundBrush = PdfBrushes.White;
defStyle.BorderPen = borderPen;
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[1].Width = 12;
#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"))
{
//// Create the Text Web Link
//PdfTextWebLink textLink = new PdfTextWebLink();
//textLink.Url = @"http://www.syncfusion.com/products/reporting-edition/pdf";
//textLink.Text = "Know more...";
//textLink.Brush = PdfBrushes.Black;
//PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
//textLink.Font = font;
//textLink.DrawTextWebLink(args.Graphics, new PointF(x, y));
////textLink.DrawTextWebLink(args.Graphics, new PointF(args.Bounds.X + 2 * (args.Bounds.Width / 3), args.Bounds.Y));
PdfTextWebLink textLink = new PdfTextWebLink();
textLink.Url = args.Value;
textLink.Text = " Klik hier: " + args.Value;
textLink.Brush = PdfBrushes.Black;
PdfFont smallFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 5f);
textLink.Font = smallFont;
textLink.DrawTextWebLink(args.Graphics, new PointF(x, y));
}
}
catch (System.Exception ex)
{
FoutOmschrijving = "Er is een fout opgetreden in de functie pdfLightTable_BeginCellLayout()." + System.Environment.NewLine + ex.Message;
Debug.Print(ex.Message);
}
}
#endregion