I'm using aspnet Document.Reports to create a PDF for download. How do I attach a hyperlink to an image?
Thanks
Abbott
Hello AbbottF,
Thank you for your question.
I am not sure how you create the PDF document, I will assume that you use dynamic approach.
My suggestion is to use CellExporting server event, and from there to modify the cell element content.
To be more specific AddContent Method can accept image and hyperlink data, I think this is what you are searching.
Sample is attached.
Code snippet:
protected void dExporter_CellExporting(object sender, Infragistics.Web.UI.GridControls.DocumentCellExportingEventArgs e){ if (e.GridCell != null && e.GridCell.Column.Key == "Test") { if (e.GridCell.Row.Index == 2) { Infragistics.Documents.Reports.Report.Text.Style bluelink = new Infragistics.Documents.Reports.Report.Text.Style(new Font("Aria", 8, FontStyle.Underline), Brushes.Blue);
string reff = e.GridCell.Value.ToString(); var regexHref = new Regex("<a [^>]*href=(?:'(?<href>.*?)')|(?:\"(?<href>.*?)\")", RegexOptions.IgnoreCase); var regexSrc = new Regex("<img [^>]*src=(?:'(?<src>.*?)')|(?:\"(?<src>.*?)\")", RegexOptions.IgnoreCase); var urls = regexHref.Matches(reff).OfType<Match>().Select(m => m.Groups["href"].Value).SingleOrDefault(); var srcs = regexSrc.Matches(reff).OfType<Match>().Select(m => m.Groups["src"].Value).SingleOrDefault(); Infragistics.Documents.Reports.Graphics.Image img = new Infragistics.Documents.Reports.Graphics.Image(HttpRuntime.AppDomainAppPath + srcs); e.ReportCellElement.AddText().AddContent(img, new Size(70, 70), Infragistics.Documents.Reports.Report.ImageAlignment.Middle, new Hyperlink(urls)); }
.....
I used one of your samples (the generated pdf is attached).
The code I use to insert the image is:
IBand band = reportSection.AddBand(); band.Height = new FixedHeight(100); band.Margins.Vertical = 5; band.Paddings.All = 5; // Here you can see how to create a gradient color background band.Background = new Background(new LinearGradientBrush(new Color(198, 212, 232), Colors.White, 90)); // Header IText text = band.AddText(); text.Alignment.Horizontal = Alignment.Right; if (customer.EMail == "") { text.AddContent( "YOUR SHOPPING CART", invoiceHeaderFontStyle); } else { text.AddContent( "YOUR SHOPPING CART", invoiceHeaderFontStyle, new Hyperlink(shoppingCartUri)); } // Here we add the IG logo System.Drawing.Image nativeImage = System.Drawing.Image.FromFile( HttpContext.Current.Server.MapPath( "/images/mktg/KboPromoHeader Small.png")); Infragistics.Documents.Reports.Graphics.Image image = new Infragistics.Documents.Reports.Graphics.Image(nativeImage, Colors.White); band.AddImage(image);
An additional question is - how do I keep the transparency of the png image?