How to load the image dynamically in page Report

Posted by: sparthanari on 5 October 2017, 9:12 am EST

  • Posted 5 October 2017, 9:12 am EST

    Hi,

    We are using below code for dynamically loading image in section report.

    private void AddImageControlSectionReport(Image image, float iconWidth, float iconHeight, float iconSpacing, int columnIndex, Detail details)
    {
    float iconTop = 0.02f;
    float iconLeft = columnIndex * (iconWidth + iconSpacing) + iconSpacing;

    Picture gdaPicture = new Picture();
    gdaPicture.Width = iconWidth;
    gdaPicture.Height = iconHeight;
    gdaPicture.Top = iconTop;
    gdaPicture.Left = columnIndex * (iconWidth + iconSpacing) + iconSpacing;
    gdaPicture.Image = image;
    gdaPicture.SizeMode = SizeModes.Stretch;

    details.Controls.Add(gdaPicture);
    }

    Now we are migrating from section report to Page report. But page report Image control functionality is different.

    How to migrate the same code to support page Report.

    Thanks in advance for your help.


  • Replied 7 October 2017, 11:29 am EST

    Hi ,

    I have modified the above code (from section Report) to support Page report. The modified code given below.

    private void AddImageControlPageReport(System.Drawing.Image image, float iconWidth, float iconHeight, float iconSpacing, int columnIndex, Body body, ref float top)
    {

    float iconTop = 0.02f;
    float iconLeft = columnIndex * (iconWidth + iconSpacing) + iconSpacing;
    // Image
    GrapeCity.ActiveReports.PageReportModel.Image gdaImage = new GrapeCity.ActiveReports.PageReportModel.Image();
    gdaImage.Width = new Length(iconWidth, Length.Unit.Inches);
    gdaImage.Height = new Length(iconHeight, Length.Unit.Inches);
    gdaImage.Top = new Length(iconTop, Length.Unit.Inches);
    gdaImage.Left = new Length(columnIndex * (iconWidth + iconSpacing) + iconSpacing, Length.Unit.Inches);

    gdaImage.Source = GrapeCity.ActiveReports.Extensibility.Rendering.Components.ImageSource.External;
    gdaImage.Sizing = ImageSizing.Fit;
    gdaImage.MIMEType = "image/png";

    //? properties expecting ExpressionInfo string.
    gdaImage.Value = "";[b][/b]
    body.ReportItems.Add(gdaImage);
    }

    How to convert image object (System.Drawing.Image image) or assign the image object to “gdaImage.Value” property ?

    Please help me to solve the issue.

  • Replied 10 October 2017, 7:35 am EST

    Hello,

    You can use the code as follows to add an image to Page report at run time:

    GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport();
    // Load a report definition file.
    rpt.Load(new System.IO.FileInfo(Application.StartupPath + @"\..\..\PageReport1.rdlx"));

    GrapeCity.ActiveReports.PageReportModel.Image gdaImage = new GrapeCity.ActiveReports.PageReportModel.Image();
    var fp = (GrapeCity.ActiveReports.PageReportModel.FixedPage)rpt.Report.Body.ReportItems[0];
    fp.Pages[0].ReportItems.Add(gdaImage);
    gdaImage.Width = new Length(7, Length.Unit.Centimeters);
    gdaImage.Height = new Length(5, Length.Unit.Centimeters);
    gdaImage.Top = new Length(0.5, Length.Unit.Centimeters);
    gdaImage.Left = new Length(0.6, Length.Unit.Centimeters);
    gdaImage.Source = GrapeCity.ActiveReports.Extensibility.Rendering.Components.ImageSource.External;
    gdaImage.Sizing = ImageSizing.Fit;
    gdaImage.MIMEType = "image/jpg";
    gdaImage.Name = "customImage";
    gdaImage.Value = Application.StartupPath + @"\..\..\owlimage.jpg";
    rpt.Run();
    GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(rpt);
    viewer1.LoadDocument(pageDocument);


    Please refer to the attached sample application for better understanding.

    Thanks,
    Deepak Sharma
    ARAddImageToPagereport.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels