As many of you might have figured out by now Reporting Services 2005 doesn’t support rotating objects or multiple orientation (as in per sub report). Depending on your situation there might still be an answer. I was in a situation recently where I need certain pages of a report in landscape and some in portrait. I was told that this is not possible out of the box in Reporting Services 2005 but have since found a workaround that might work for you. Microsoft has done a great job with making SSRS an open architecture and the web services are a key part of this approach. Behind the scenes of your Report Viewer control (in “remote” mode) it is actually making a request to the Render command of the SSRS Web Service. So to pull of the rotation of a report I created a new web page with a web reference to the ReportService. I then request the report in IMAGE format and store the byte[]. I create a new Bitmap object and stream in the byte[] so that I have full control over my newly created report Image in GDI.NET. Bitmap supports a RotateFlip method that has just what we need and then I save the Bitmap to the Response.OutputStream object. You are probably familiar with the concept of pointing an Image to an ASPX page that dynamically generates the bytes of the Image and this solution is no different. Once you have an ASPX that can generate a rotated Image of the report then you treat it just like any other Image in the Report or on a WebForm.
This solution was adapted from Bryan Kelly’s post on Programmatically Printing RS 2000 Reports found HERE
The source code for the page is below:.Drawing.Imaging;
using System.Drawing;
using System.Runtime.InteropServices; // For Marshal.Copy
using System.IO;
using System.Web.Services.Protocols;
public partial class ASR_ReportAsImage : System.Web.UI.Page
{
ReportService.ReportingService rs;
private byte[][] m_renderedReport;
private System.Drawing.Graphics.EnumerateMetafileProc m_delegate = null;
private System.IO.MemoryStream m_currentPageStream;
private System.Drawing.Imaging.Metafile m_metafile = null;
int m_numberOfPages;
protected void Page_Load(object sender, EventArgs e)
{
rs = new ReportService.ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
PrintReportAsImage();
}
public byte[][] RenderReport(string reportPath)
{
// Private variables for rendering
string deviceInfo = null;
string format = “IMAGE”;
Byte[] firstPage = null;
string encoding;
string mimeType;
ReportService.Warning[] warnings = null;
ReportService);
}
return pages;
}
public bool PrintReportAsImage()
{
this.RenderedReport = this.RenderReport(“/ASR Prototype/ASR_TransactionOverview”);
// Wait for the report to completely render.
if (m_numberOfPages < 1)
return false;
for (int i = 0; i < m_renderedReport.Length; i++)
{
//write all of the pages to stream….
System.IO.MemoryStream memstream = new System.IO.MemoryStream(m_renderedReport[i], false);
System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(memstream, true);
//now rotate the bitmap 90 degrees
oBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
//write it to the output stream
Response.ContentType = “image/jpeg”;
oBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
}
return;
}
}
}
Wow – you think there’d be an easier way. If you read the comments in this article, Brian Welker mentiones a future capability of creating report ‘sections’ where each section can have it’s own orientation.
He posted that in 2005 and nothing has come of it that I’m aware of. It seems like this is a need to have.
Comment by Justin Saraceno — May 22, 2007 @ 5:00 pm
I was wondering if you know of a way to rotate a text box so that it is 180 degrees from the position of a tb-lr write mode so I read it from bottom to top. Please let me know. Thanks
I hear you can create a class that converts a string to an image and then flip the image so that it is rotated the way that I wanted
Thanks in advance.
Comment by Kenny — May 5, 2008 @ 11:51 pm
Kenny,
I would say that it depends on how many items you need to rotate. If just the textbox for readonly/printing purposes then you could do the above method or just use an image of a textbox.
Regards,
-Ben
Comment by ben — May 6, 2008 @ 7:01 am
Review this:
Comment by IntenseAnalytics — February 1, 2009 @ 10:10 pm
Using an image is nice but text is necessary. And as I see, that is not possible event with SSRS 2008 unfortunately.
Comment by Eralper — March 12, 2009 @ 6:43 am
I think I might handle text as an image if I absolutely needed it rotated. You could use the same method as above and just post the text to a web page that would create an image of the rotated text.
Comment by Ben — March 12, 2009 @ 7:41 am
Understanding that, many are also discovering that the ceiling is a great way to add a good dose
of color into the interior design of their
home. What are your top priorities and what do you want to
spend? Let your personality and taste glow in your office using the right
accessories, color combinations and artwork.
Comment by Clicking Here — July 29, 2012 @ 10:16 am