Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dynamically center an image in a MS Reporting Services report?

Out of the box, in MS Reporting Services, the image element does not allow for the centering of the image itself, when the dimensions are unknown at design time. In other words, the image (if smaller than the dimensions allotted on the design surface) will be anchored to the top left corner, not in the center.

My report will know the URL of the image at runtime, and I need to be able to center this image if it is smaller than the dimensions specified in my designer.

like image 278
Ian Robinson Avatar asked Aug 07 '08 20:08

Ian Robinson


People also ask

How do I center an image in SSRS?

It is not possible to directly do auto-align / docking. By default images are placed at the top left of a cell, and will expand from there based on the Display properties you set. In order to position a static image we can either resize the cell the image is in, or modify the padding settings.

How do you insert an image into a report?

To embed an image in a reportIn report design view, on the Insert tab, click Image. On the design surface, click and then drag a box to the desired size of the image. In the General page of the Image Properties dialog box, type a name in the Name text box or accept the default.


1 Answers

Here is how I was able to accomplish this. With help from Chris Hays

Size the image to be as big as you would want it on the report, change "Sizing" property to "Clip".

Dynamically set the image's left padding using an expression:

=CStr(Round((4.625-System.Drawing.Image.FromStream(System.Net.WebRequest.Create(Parameters!LogoURL.Value).GetResponse().GetResponseStream()).Width/96)/2,2)) & "in"

Dynamically set the image's top padding using an expression:

=CStr(Round((1.125-System.Drawing.Image.FromStream(System.Net.WebRequest.Create(Parameters!LogoURL.Value).GetResponse().GetResponseStream()).Height/96)/2,2)) & "in"

The first modification made to Chris's code was to swap out the dimensions of my image element on the report (my image was 4.625x1.125 - see numbers above).

I also chose to get the stream from a URL instead of the database. I used WebRequest.Create.GetResponse.GetResponseStream do to so.

So far so good - I Hope that helps!

like image 189
Ian Robinson Avatar answered Oct 12 '22 14:10

Ian Robinson