Page 1 of 1
Caching icons used in a table
Posted: Thu Oct 04, 2012 1:50 pm
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
Re: Caching icons used in a table
Posted: Fri Oct 05, 2012 2:53 pm
by HighAley
Hello.
Sorry, we need a little more time to prepare an answer for you.
Thank you.
Re: Caching icons used in a table
Posted: Mon Oct 08, 2012 9:33 am
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.
Re: Caching icons used in a table
Posted: Mon Oct 08, 2012 1:23 pm
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.
Re: Caching icons used in a table
Posted: Mon Oct 08, 2012 2:46 pm
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.
Re: Caching icons used in a table
Posted: Tue Oct 09, 2012 9:27 am
by Alex K.
Hello,
Can you please send us a sample project which reproduces the issue for analysis.
Thank you.
Re: Caching icons used in a table
Posted: Thu Oct 11, 2012 10:08 am
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
Re: Caching icons used in a table
Posted: Fri Oct 12, 2012 12:32 pm
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.
Re: Caching icons used in a table
Posted: Fri Oct 12, 2012 1:23 pm
by John
Hallo Aleksey,
that's great! Such a simple solution. Now I can relax and enjoy the weekend.
Best regards,
John K.
Re: Caching icons used in a table
Posted: Fri Oct 12, 2012 1:33 pm
by Alex K.
Hello,
Great!
Have a nice weekend!