This is a migrated thread and some comments may be shown as answers.

Convert to image

1 Answer 352 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 14 Nov 2007, 05:04 PM
Hello,

First, my goal is to take a report and convert it to a image.  To that end I found some sample code (shown below) which does that
The code creates a jpeg, but only the first page is rendered.  Is this code incomplete?

Scott

Report1 report1 = new Report1();
string mimType = string.Empty;
string extension = string.Empty;
Encoding encoding =
null;
try
{
 
Hashtable deviceInfo = new Hashtable();
 deviceInfo[
"OutputFormat"] = "JPEG";
 
byte[] buffer = Telerik.Reporting.Processing.ReportProcessor.Render(
     
"IMAGE", report1, deviceInfo, out mimType, out extension, out encoding);
 
using (MemoryStream stream = new MemoryStream(buffer))
 {
   
using (Image img = Image.FromStream(stream))
   {
     img.Save(
@"c:\" + report1.GetType().Name + "." + extension,
       System.Drawing.Imaging.ImageFormat.Jpeg);
   }
 }
}
catch (Exception ex)
{
 MessageBox.Show(ex.ToString());
}

1 Answer, 1 is accepted

Sort by
0
Hrisi
Telerik team
answered on 15 Nov 2007, 04:11 PM
Hello Scott,

In most of the cases the report can contains many pages and only image format supporting pages is Tiff. 
Please, try the following code:

            Report1 report1 = new Report1();  
            string mimType = string.Empty;  
            string extension = string.Empty;  
            Encoding encoding = null;  
            try 
            {  
                byte[] buffer = Telerik.Reporting.Processing.ReportProcessor.Render(  
                    "IMAGE", report1, nullout mimType, out extension, out encoding);  
 
                using (FileStream stream = File.Create(@"c:\" + report1.GetType().Name + "." + extension))  
                {  
                        stream.Write(buffer,0,buffer.Length);  
                }  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.ToString());  
            } 

This code will produce the file Report1.tif with all report pages. This file can be used to extract for example pages to separate image files as well.

I hope this information helps. Thank you.

Regards,
Hrisi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Hrisi
Telerik team
Share this question
or