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

TIf Rendering Extension Not Working

3 Answers 239 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Doug Odegaard
Top achievements
Rank 2
Doug Odegaard asked on 22 Jan 2008, 07:43 PM

I have used SP1 successfully to render a CCITT G4 compression report through the web viewer.  But now when I automate it through code to churn out many reports in an automated fashion is goes back to LZW compression which is not what I want.  Here is what i have in my code....please help!  Am I formatting my extension wrong or feeding variables to the Render method incorrectly.  The DPI changes but the compression stays as LZW.  Thanks in advance for your help.
Doug

            string mimType = string.Empty;  
            string extension = string.Empty;  
            Encoding encoding = null;  
            Report1 report1 = new Report1();  
 
                Hashtable deviceInfo = new Hashtable();  
                deviceInfo["OutputFormat"] = "TIFF";  
                deviceInfo["TiffCompression"] = "ccitt4";  
                deviceInfo["DpiX"] = 300;  
                deviceInfo["DpiY"] = 300;  
                byte[] buffer = Telerik.Reporting.Processing.ReportProcessor.Render(  
                    "TIFF300", report1, deviceInfo, out mimType, out extension, out encoding);  
                using (MemoryStream stream = new MemoryStream(buffer))  
                {  
                    using (System.Drawing.Image img = System.Drawing.Image.FromStream(stream))  
                    {  
                        img.Save(@"c:\temp\" + report1.GetType().Name + "." + extension,  
                          System.Drawing.Imaging.ImageFormat.Tiff);  
                    }  
                } 

My extension in the web.config look like this....

                <Extension name="TIFF_CCITT4_300" 
            type="Telerik.Reporting.ImageRendering.ImageReport, Telerik.Reporting.Processing, Version=2.0.1.0, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" 
            description="TIFF file (CCITT Group 4 300dpi)">  
                    <Parameters> 
                        <Parameter name="TiffCompression" value="ccitt4" /> 
                        <Parameter name="DpiX" value="300" /> 
                        <Parameter name="DpiY" value="300" /> 
                    </Parameters> 
                </Extension> 
 
                <Extension name="TIFF300" 
            type="Telerik.Reporting.ImageRendering.ImageReport, Telerik.Reporting.Processing, Version=2.0.1.0, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" 
            description="TIFF file (CCITT Group 4 300dpi)">  
                    <Parameters> 
                        <Parameter name="TiffCompression" value="ccitt4" /> 
                        <Parameter name="DpiX" value="300" /> 
                        <Parameter name="DpiY" value="300" /> 
                    </Parameters> 
                </Extension> 

3 Answers, 1 is accepted

Sort by
0
Milen | Product Manager @DX
Telerik team
answered on 23 Jan 2008, 03:33 PM
Hello Doug Odegaard,

Using your project I was able to render programmatically your report as a bi tonal image (The only thing I had to change is to add one column in the table of the DB ).

Please double check the output of the rendering operation on your machine. Find attached the image produced with your own code.

Something more. There is no need to send through DeviceInfo settings that you already have set in the configuration file. So instead of

                Hashtable deviceInfo = new Hashtable();
                deviceInfo["OutputFormat"] = "TIFF";
                deviceInfo["TiffCompression"] = "ccitt4";
                deviceInfo["DpiX"] = 300;
                deviceInfo["DpiY"] = 300;
                byte[] buffer = Telerik.Reporting.Processing.ReportProcessor.Render(
                    "TIFF300", report1, deviceInfo, out mimType, out extension, out encoding);

it is good enough to use

                byte[] buffer = Telerik.Reporting.Processing.ReportProcessor.Render(
                    "TIFF300", report1, null, out mimType, out extension, out encoding);

because TIFF300 is already preconfigured with those settings in the configuration of Telerik Reporting.

I hope that information helps.

Regards,
Milen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Doug Odegaard
Top achievements
Rank 2
answered on 23 Jan 2008, 05:07 PM
Milen,
Thanks for responding but the Report1.tif file you sent to me is actually still LZW compression.  The project works just fine.  The Report Viewer can export to G4 just fine.  But when I use the render code you sent me the compression is still LZW.  I expect the TIF Rendering Extension to work through the Render method just like doing it manually in the viewer.  Could you please run it again and check the compression/format.

Thanks.
Doug
0
Milen | Product Manager @DX
Telerik team
answered on 24 Jan 2008, 11:57 AM
Hi Doug,

After second look at your code I believe we found out where is the problem. It is in the way you are using the Image.Save method. By default, it uses LZW compression, and if you want to save a Image with other compression, you have to pass additional parameters.

Actually, it is not necessary to create Image at all. You can just save the bytes returned from our Render method using a FileStream.

So, instead of

            using (MemoryStream stream = new MemoryStream(buffer))
            {
                using (System.Drawing.Image img = System.Drawing.Image.FromStream(stream))
                {
                    img.Save(@"c:\temp\" + report1.GetType().Name + "." + extension,
                      System.Drawing.Imaging.ImageFormat.Tiff);
                }
            }


you can just use

            string fileName = @"c:\temp\" + report1.GetType().Name + "." + extension;
            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                fs.Write(buffer, 0, buffer.Length);
            }


Additional info:
Review the Saving a report into PDF format programmatically article, as a sample export.

Let us know if you need any further assistance.

Greetings,
Milen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Doug Odegaard
Top achievements
Rank 2
Answers by
Milen | Product Manager @DX
Telerik team
Doug Odegaard
Top achievements
Rank 2
Share this question
or