Page 1 of 2

How to load an image dynamically to a report JS?

Posted: Tue Jul 11, 2017 10:04 am
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

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

Posted: Wed Jul 12, 2017 10:24 am
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);

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

Posted: Thu Jul 13, 2017 8:50 pm
by Alex K.
Hello,

Thank you for your solution.

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

Posted: Mon Jul 24, 2017 6:38 am
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);

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

Posted: Mon Jul 24, 2017 11:16 am
by HighAley
Hello.

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

Thank you.

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

Posted: Thu Nov 09, 2017 1:40 am
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

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

Posted: Sun Nov 12, 2017 4:39 pm
by Andrew
ruchira,

Does the code offered by iphayc helped you?

Thank you.

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

Posted: Fri Oct 25, 2019 1:22 am
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

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

Posted: Mon Oct 28, 2019 11:24 am
by Lech Kulikowski
Hello,

Please clarify which version are you use?

Thank you.

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

Posted: Wed Nov 06, 2019 2:37 am
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