Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
MSBI 49
#BI 39
BRH 39
SSRS 35
#MSBI 29
SQL Server 28
#SSRS 22
SSAS 22
#SQL Server 21
Reporting 19

Archive · View All
April 2010 8
May 2010 7
January 2013 6
November 2012 5
March 2012 5
July 2012 4
January 2012 4
October 2011 4
June 2010 4
February 2013 3

Some Random Thoughts

Rotate Text in SSRS

Jan 27 2011 12:58PM by Jason Thomas   

Sometimes we get pampered so much by modern technology that we tend to raise the bar of necessity towards the fringes of luxury. 10 years back, a mobile phone was a luxury in my native place. Today, even school children carry one along with them and most of them take it as granted. Similarly, I had been so used to the rich features of SSRS 2008 R2 that I often forget that this feature never existed in the previous versions. Take this case where one of the forum users had asked me how to rotate text in the matrix column header of a SSRS report as shown below.

Being used to SSRS 2008 R2, I thought rotating text to 270° was a pretty easy solution but I conveniently forgot that this feature was not available directly in SSRS 2008 and below versions. So I decided to blog down the solution for both SSRS 2008 R2 and other versions. For detailing the solution, I have already created a dataset which will give me the greenhouse emissions of the states in the USA by sector. The requirement is to display all the states in the column header and the optimal way would be to rotate it and display vertically.

(I) SSRS 2008 R2

1) Select the column whose text you want to rotate and press F4 to bring up the properties panel.

2) Select the WritingMode property and select the value as Rotate270. (The Vertical selection will rotate the text by 90° instead of 270°)

3) Now you can preview the report and the header text should be rotated by 270°.

You can also change the horizontal and vertical alignment as needed by selecting the appropriate values in the TextAlign and VerticalAlign properties.

(II) SSRS 2008 and 2005

Since this option is not available out of the box for older versions, we will have to use custom code in our report.

1) Open the report properties and paste the following custom code in the Code tab of report properties.

(Note : I am in no way a VB.net coding expert and the following piece of code was collected by me quite some years ago and have lost track of it’s origins; hence could not attribute it to the original author. If you are or know the author, please let me know so that I can link it to you/the original post. I have also made some modifications and if any of you guys feel that it can be improved, please paste the improved code in the comments sections so that it can be used by others)


Function LoadImage(ByVal sImageText as String,ByVal sImageTextMax as String)
sImageTextMax= sImageTextMax.PadRight(40)
Dim iFontSize As Integer = 10 ‘//Change this as needed
Dim bmpImage As New Drawing.Bitmap(1, 1)
Dim iWidth As Integer = 0
Dim iHeight As Integer = 0

'// Create the Font object for the image text drawing.
Dim MyFont As New Drawing.Font("Arial", iFontSize, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point)
'// Create a graphics object to measure the text's width and height.
'Graphics(MyGraphics = Graphics.FromImage(bmpImage))
Dim MyGraphics As Drawing.Graphics = Drawing.Graphics.FromImage(bmpImage)
'// This is where the bitmap size is determined.
iWidth = MyGraphics.MeasureString(sImageTextMax, MyFont).Width
iHeight = MyGraphics.MeasureString(sImageTextMax, MyFont).Height
'// Create the bmpImage again with the correct size for the text and font.
'bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iWidth, iHeight))
bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iHeight, iWidth))
'// Add the colors to the new bitmap.
MyGraphics = Drawing.Graphics.FromImage(bmpImage)
MyGraphics.Clear(Drawing.Color.Green)
MyGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
MyGraphics.TranslateTransform(0, iWidth)
MyGraphics.RotateTransform(270)

MyGraphics.DrawString(sImageText, MyFont, New Drawing.SolidBrush(Drawing.Color.White), 0, 0)
MyGraphics.Flush()
Dim stream As IO.MemoryStream = New IO.MemoryStream
Dim bitmapBytes As Byte()
'Create bitmap
bmpImage.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)
bitmapBytes = stream.ToArray
stream.Close()
bmpImage.Dispose()
Return bitmapBytes
End Function

The above code converts Now your code window should look like this

2) Go to the References tab and add a reference to the System.Drawing assembly.

3) Click OK to save and close the report properties. Then drag and drop an image item from the toolbox to the column header which will popup the Image Properties window as shown below.

Make sure that the

(a) image source is set as Database,

(b) MIME type is set as image/jpeg

(c) Use this field has the following expression

=Code.LoadImage(Fields!State.Value,"District of Columbia")

In the above expression, Fields!State.Value is the field value whose text should be rotated (in this case - State). It can be substituted with any string value also. The second parameter is ideally for the longest string in the values for Fields!State.Value and is just used so that all the text values start at the same position and for general aligning purposes. In the above example, I have directly hardcoded it as “District of Columbia” but you can change it such that the field with the maximum length is passed.

4) Click on OK and then preview the report. Now you should be able to see the report as shown below

In case you are not getting the report properly, make sure that

(a) Image properties should be set as Original Size

(b) there should be a grouping on the column where the image is placed by the Field that you want to group by, else only one value would be displayed.

I am sure there is more scope for improvement in the VB.NET code like adding a code such that the text can be left, right or centre aligned, reducing the padding in the left hand side, etc. Feel free to modify and improve the code.

Tags: SSRS, BRH, MSBI, Reporting, SQL Server, #BI, #SSRS, #SQL Server, #MSBI,


Jason Thomas
19 · 9% · 2997
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • Hi jason, When i change the rotatetransform from 270 to 45, it does not work. Any help would be appreciated Thanks

    commented on Jul 12 2012 2:35PM
    V Shah
    252 · 1% · 176
  • It seems to be working for me, can u let me know what is not working? Is there no change to the image at all? And also give your software versions, so that I can try to reproduce

    commented on Jul 12 2012 2:41PM
    Jason Thomas
    19 · 9% · 2997

Your Comment


Sign Up or Login to post a comment.

"Rotate Text in SSRS" rated 5 out of 5 by 2 readers
Rotate Text in SSRS , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]