How to set dynamically height/width of an external image in rdlc report?

It seems that there is no way to dynamically set the height and width of an external image used in rdlc report, but here a workaround to make it possible

  1. Add image to you Report
  2. On the image properties, set it to use External image source and use a report parameter to set which image to use
  3. On image, set "keep original size"

Edit: You may also generate such "padding image" dynamically to allow different widths, for example:
public void GenerateReport(int width, int height)
    {
        var image =Bitmap.FromFile("your image path"); //you can use stream or other way to get the image
        using (var g = Graphics.FromImage(image))
        {
            g.Clear(Color.Transparent);
            g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, width, height); // here will change the size to fit in report
        }
        MemoryStream ms = new MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

        // and pass the image to report
        reportViewer.EnableExternalImages = true;
        reportViewer.SetParameters(new ReportParameter("dynamicimage", image)); // you can use the image it self or pass the stream and change the report itself 
     }
for full example contact me on twitter @msalem2020

Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.