Caching icons used in a table

Stimulsoft Reports.NET discussion
Post Reply
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Caching icons used in a table

Post by John »

Hallo Support,

I am using Stimulsoft.Base.dll and Stimulsoft.Report.dll (version 2012.2.1400.0) together with c# to dynamically generate pdfs containing 1 or more tables. In the attached example you can see a table which contains a lot of icons which are mostly just of two different types (here: green ticks and red hyphens) and are displayed many times. The image for each icon cell in the table is assigned using the event:

Code: Select all

cell.GetImageData += this.TableCell__GetImage;
This event eventually does the following:

Code: Select all

                using (var ms = new MemoryStream(imageArray))
                    e.Value = Image.FromStream(ms);
Up to now, this code has run on our server and RAM was no problem. Currently, we aim to provide users with an offline version for them to install at work. The problem now is that especially reports with a lot of icons are using up a lot of RAM (e.g. 700MB when I produced the attachment). Is there a way I can store the icons in the report just once and then somehow reference them in the table cells?

By the way, I tried using the following:

Code: Select all

StiOptions.Engine.ImageCache.Enabled = true; 
StiOptions.Engine.ImageCache.CachePath = "image.cache";
- all my images disappeared! I also found "StiReport.StoreImagesInResources" but could not find any information on it.
Finally, I tried

Code: Select all

myReport.ReportCacheMode = StiReportCacheMode.Auto;
but there was no noticeable improvement in the RAM used.

Thanks and regards,

John Kitching
Attachments
SamleReport.pdf
Sample with table containing icons
(315.68 KiB) Downloaded 490 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Caching icons used in a table

Post by HighAley »

Hello.

Sorry, we need a little more time to prepare an answer for you.

Thank you.
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Re: Caching icons used in a table

Post by John »

Hallo Aleksey,

just as an aside: I modified the code so that each image cell gets its data directly from the assigned DataTable, as in:

Code: Select all

cell.DataColumn = "TheDataTable.TheColumn";
instead of

Code: Select all

cell.GetImageData += this.TableCell__GetImage;
However, this made no difference to the amount of RAM used on rendering.

Do you have any idea when you could give me some further information on this issue?

Thanks and best regards,

John K.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Caching icons used in a table

Post by HighAley »

Hello.

You create a new object with image every time you need to show it.
You should create 2 variables with type Image in your report and use them.

Thank you.
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Re: Caching icons used in a table

Post by John »

Hallo Aleksey,

I have tried out what you suggested. Each table cell which requires an icon fires the "GetImageData" event and now gets its image from a report variable. This is the code which does it:

Code: Select all

        private Image AssignAndRetrieveIconVariable(string iconName)
        {
            // is the variable already there?
            var varName = string.Format("Icon_{0}", iconName);
            if (this.tableReport.Dictionary.Variables == null)
                this.tableReport.Dictionary.Variables = new StiVariablesCollection();
            if (!this.tableReport.Dictionary.Variables.Contains(varName))
            {
                // get the icon and save to the variable
                byte[] imageArray = this.reportResourceUtils.GetSymbolIcon(iconName);
                using (var ms = new MemoryStream(imageArray))
                {
                    this.tableReport.Dictionary.Variables.Add(new StiVariable(varName, Image.FromStream(ms)));
                }
            }

            return this.tableReport.Dictionary.Variables == null ? null : this.tableReport.Dictionary.Variables[varName].ValueObject as Image;
        }
The code is called in the event using

Code: Select all

e.Value = this.AssignAndRetrieveIconVariable(myIconKey);
I ran the code using my silverlight tester which calls a COM+ server object (written in c#) which then calls the ReportGenerator. This is the setup we are using to analyse the new offline product to be installed on the user's machine.
Unfortunately, I could not see any improvement in the RAM used to produce the pdf (see attachments).

Perhaps I have misunderstood your solution. Please let me know.

Best regards,

John K.
Attachments
SampleReport2.pdf
The pdf produced
(316.14 KiB) Downloaded 1171 times
Max memory used
Max memory used
MemoryUsage.jpg (37.19 KiB) Viewed 2436 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Caching icons used in a table

Post by Alex K. »

Hello,

Can you please send us a sample project which reproduces the issue for analysis.

Thank you.
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Re: Caching icons used in a table

Post by John »

Hallo Aleksey,

I've created a project which does the basics of what my normal code does. The resulting pdf can be seen in the attachment. The code dynamically creates the table using a template (in CommonTemplate.cs) which is just for formatting. The icons are stored in variables in the report and are accessed in the table cells using the cell.GetImageData event. On my machine, the RAM peaks at about 1.3Gbytes during report rendering. In our real application we have about 40 icons in total which we use in these types of dynamically-created tables.
I really hope a good solution is possible for drastically reducing the amount of RAM used.

Thanks and best regards,

John K
Attachments
StimulsoftTableTester.zip
Test project
(5.92 MiB) Downloaded 193 times
TableReport.pdf
Resulting pdf
(298.75 KiB) Downloaded 525 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Caching icons used in a table

Post by HighAley »

Hello.

The method that we provided before is good for compiled report.
But in your case the ValueObject property every time returns a new object.
We've modified your code. It is in the attachment.

Thank you.
Attachments
DynamicTable.cs
(18.27 KiB) Downloaded 187 times
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Re: Caching icons used in a table

Post by John »

Hallo Aleksey,

that's great! Such a simple solution. Now I can relax and enjoy the weekend.

Best regards,

John K.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Caching icons used in a table

Post by Alex K. »

Hello,

Great!
Have a nice weekend!
Post Reply