In this article, we will explore what thumbnails (also referred to as previews) are for reports, dashboards, and PDF forms in Stimulsoft products. Thumbnails are displayed, for example, in the report viewer and allow users to quickly and visually identify the content of a resource. Understanding how thumbnails work is useful when working with Stimulsoft Demo, Stimulsoft Server, and Stimulsoft Cloud. You can see thumbnails in action, for instance, here - when the sidebar is collapsed, thumbnails are displayed instead of the resource list.
Stimulsoft products allow for both automatic generation of thumbnails and manual control over the process using the special StiThumbnailHelper class. Additionally, you can use a custom image instead of an automatically generated thumbnail.
No additional action is required from the user. In this case, a thumbnail is generated and saved, and it is used until it is deleted (or the report itself is deleted). The main limitation is that the thumbnail doesn’t update when the report is modified. To update it, the old thumbnail file must be manually deleted and regenerated.
This way, thumbnails for reports can be generated at any time as needed.
The image is stored inside the report file. If you add or reference a large image file, it will increase the overall size of the report file. Earlier, we mentioned that automatically generated thumbnails can only be updated by deleting the existing preview file. However, when integrating Stimulsoft into your own application, you can dynamically generate a new thumbnail and assign it directly to the ReportImage property.
Thumbnails in Stimulsoft provide a simple and effective way to visually represent reports, dashboards, and forms. They can be generated automatically or manually, and even replaced with custom images. Thanks to the StiThumbnailHelper class, developers have a flexible tool for managing thumbnails in any integration scenario. Proper use of this feature improves navigation, enhances the user interface, and enriches the overall experience of interacting with reports in an application.
Automatic thumbnail generation
Thumbnails are generated automatically when a report is added to:- Stimulsoft Server and Stimulsoft Cloud – upon the first addition to a workspace.
- Stimulsoft Demo – upon the first addition to the resource list.
No additional action is required from the user. In this case, a thumbnail is generated and saved, and it is used until it is deleted (or the report itself is deleted). The main limitation is that the thumbnail doesn’t update when the report is modified. To update it, the old thumbnail file must be manually deleted and regenerated.
Managing thumbnails using StiThumbnailHelper
When integrating Stimulsoft into a custom project or application, you can use the StiThumbnailHelper class to control the thumbnail generation process.- GetThumbnailPath(string path) generates the path to the .thumb thumbnail file for a given report, taking into account the operating system’s display scaling.
- SaveThumbnail(StiReport report, string path) returns an array of image bytes, i.e. a thumbnail of the first rendered report page, to the .thumb file. This method can be used only for a rendered report, or you can call report.Render().
- GetThumbnail(string path) returns the byte array of the specified report’s thumbnail from the .thumb file. If the file doesn’t exist, it returns null.
- GetThumbnailFromTemplateAsync(string path) asynchronously retrieves a report thumbnail from a .mrt template file.
- GetThumbnailFromTemplate(string path, bool skipImage = false) synchronously creates a StiThumbnailReport object, which contains the path, report name, dashboard flag (`IsDbs`), and image. If a thumbnail was previously saved, it is loaded. If not, the report is loaded, the image is generated, and a .thumb file is saved. This method also detects whether the source is a dashboard or a regular report.
This way, thumbnails for reports can be generated at any time as needed.
Using the Report Image property
Each report, dashboard, or PDF form template can include its own image in the Report Image property. This image will be used as the thumbnail instead of an automatically generated preview. This applies in products such as Stimulsoft Demo, Stimulsoft Server, and Stimulsoft Cloud. For example, you can set a static image that will be displayed in the interface regardless of the actual report content. NOTE:The image is stored inside the report file. If you add or reference a large image file, it will increase the overall size of the report file. Earlier, we mentioned that automatically generated thumbnails can only be updated by deleting the existing preview file. However, when integrating Stimulsoft into your own application, you can dynamically generate a new thumbnail and assign it directly to the ReportImage property.
...
//Load report
var report = new StiReport;
var templatePath = "Reports\\MyReport.mrt";
report.Load(templatePath);
// Generate a new thumbnail from the report template
var thumbnail = await Stimulsoft.Wizard.Wpf.Info.Helper.StiThumbnailHelper.GetThumbnailFromTemplateAsync(templatePath);
// Convert byte array to System.Drawing.Image
using (var ms = new MemoryStream(thumbnail.Image))
{
// Assign generated thumbnail to the ReportImage property
report.ReportImage = System.Drawing.Image.FromStream(ms);
}
// Call report in designer where ReportImage will be used as the report thumbnail
report.Design();
...
In practice, this means a new thumbnail can be generated for the report at runtime and saved into the Report Image property. This allows you to update the thumbnail without deleting the existing report or its preview file.An important point – animation
There is one important aspect to consider when generating thumbnails - animation, especially in the case of dashboards. For reports, the thumbnail is generated from the first rendered page, which serves as the preview image. However, dashboards don’t have a defined rendered state, they operate in real-time. This means that if the animation of dashboard elements hasn't fully completed at the moment the thumbnail is generated, the preview might not accurately reflect the actual content. For example, a chart might appear only partially rendered. To ensure the thumbnail fully matches the intended appearance, it is important to account for the duration of animations.Thumbnails in Stimulsoft provide a simple and effective way to visually represent reports, dashboards, and forms. They can be generated automatically or manually, and even replaced with custom images. Thanks to the StiThumbnailHelper class, developers have a flexible tool for managing thumbnails in any integration scenario. Proper use of this feature improves navigation, enhances the user interface, and enriches the overall experience of interacting with reports in an application.