How to load an image dynamically to a report JS?

Stimulsoft Reports.JS discussion
ruchira
Posts: 4
Joined: Fri Jun 09, 2017 11:50 am

How to load an image dynamically to a report JS?

Post by ruchira »

I want dynamically load an image to report. I'm using stimulsoft report js viewer and i found below code available for Stimulsoft Reports.Wpf

Code: Select all

StiReport report = new StiReport();
report.Load("e:\\Report.mrt");
StiImage stiImage = report.GetComponents()["Image1"] as StiImage;
Image myImage = Image.FromFile(@"e:\Image.jpg");
stiImage.Image = myImage;
report.Show();
Please help me to convert this to JS version
Thanks
Ehsan
Posts: 100
Joined: Tue Jan 05, 2016 10:39 am
Location: Iran

Re: How to load an image dynamically to a report JS?

Post by Ehsan »

Hello
you can use below code:


Code: Select all

//Create image on Header
var sampleImage = new Stimulsoft.Report.Components.StiImage();

var stiImage = Stimulsoft.System.Drawing.Image.fromFile(your file);
stiImage.aspectRatio = true;

sampleImage.image = stiImage;

sampleImage.width = 10;
sampleImage.height = 10;
sampleImage.stretch = true
sampleImage.aspectRatio = true;

ReportTitleBand.components.add(sampleImage);
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: How to load an image dynamically to a report JS?

Post by Alex K. »

Hello,

Thank you for your solution.
ruchira
Posts: 4
Joined: Fri Jun 09, 2017 11:50 am

Re: How to load an image dynamically to a report JS?

Post by ruchira »

Thanks Ehsan for your solution and i used resource component to do this as follows

Code: Select all

var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/SimpleList.mrt");
var content = Stimulsoft.System.IO.Http.getFile("https://xxxx.blob.core.windows.net/Screenshot%20(37).jpg", true);
var resource = new Stimulsoft.Report.Dictionary.StiResource("Resource1", "Resource1", false, Stimulsoft.Report.Dictionary.StiResourceType.Image, content);
report.dictionary.resources.add(resource);
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to load an image dynamically to a report JS?

Post by HighAley »

Hello.

This code adds a resource to the report.
You could use it in your report.

Thank you.
iphayc
Posts: 1
Joined: Thu Nov 09, 2017 1:26 am

Re: How to load an image dynamically to a report JS?

Post by iphayc »

ruchira wrote:I want dynamically load an image to report. I'm using stimulsoft report js viewer and i found below code available for Stimulsoft Reports.Wpf

Code: Select all

StiReport report = new StiReport();
report.Load("e:\\Report.mrt");
StiImage stiImage = report.GetComponents()["Image1"] as StiImage;
Image myImage = Image.FromFile(@"e:\Image.jpg");
stiImage.Image = myImage;
report.Show();
Please help me to convert this to JS version
Thanks
Hi,

try this code :

Code: Select all

var report = new Stimulsoft.Report.StiReport();
		report.loadFile("e:/report.mrt");
               //create variable image and loadfile from local disk ex. location image on drive c:/
		var stiImage = Stimulsoft.System.Drawing.Image.fromFile("c:/image.jpg");		
		
               //create variable with type : image, create that variable on the report with name : var_image
		var var1 = report.dictionary.variables.getByName("var_image");	
		var1.valueObject = stiImage;		
		viewer.report = report;
		viewer.renderHtml("viewerContent");
thanks,
Ipay
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: How to load an image dynamically to a report JS?

Post by Andrew »

ruchira,

Does the code offered by iphayc helped you?

Thank you.
mbaker78
Posts: 8
Joined: Fri Sep 13, 2019 5:03 am

Re: How to load an image dynamically to a report JS?

Post by mbaker78 »

Hi,
I'm trying to do the same thing, but my logo is appearing on my report.

In the .mrt file, I created a variable called "Logo". Then placed an image box on the report and loaded the image from the variable. When I run preview the report, this all works fine.

Then when I try and run it from code, I have the following:

Code: Select all

var stiImage = Stimulsoft.System.Drawing.Image.fromFile("/reports/Logo.jpg");
var var1 = report.dictionary.variables.getByName("Logo");
var1.valueObject = stiImage;

viewer.report = report;
viewer.renderHtml('viewer');
The report is all working fine except the image/logo is not appearing.

Any help would be appreciated. Thanks
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: How to load an image dynamically to a report JS?

Post by Lech Kulikowski »

Hello,

Please clarify which version are you use?

Thank you.
mbaker78
Posts: 8
Joined: Fri Sep 13, 2019 5:03 am

Re: How to load an image dynamically to a report JS?

Post by mbaker78 »

Hi,

I'm using Version 2019.4.1
'
Edit: I ended up adding a Resource to the report (and selecting my logo) and then using this as the logo. It looks like the size of the image matters however, as this only worked for my low res logo (which is just over 100kb).

Thanks,
Michelle
Last edited by mbaker78 on Wed Nov 06, 2019 5:16 am, edited 1 time in total.
Post Reply