Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
520
Document.Reports add hyperlink to image
posted

I'm using aspnet Document.Reports to create a PDF for download. How do I attach a hyperlink to an image?

Thanks

Abbott

Parents
No Data
Reply
  • 20255
    Offline posted

    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));
      }

    .....

    ExportPDFwithHyperlinks.zip
Children