Page 1 of 1

Adding Image Resource - Image Not Showing

Posted: Fri Oct 16, 2020 9:08 am
by nickdavies07
I've attempted to add an image programmatically as a resource so the user can select their company logo which is already available in our system.
The code I've used to create the resource is

Code: Select all


	let report = new Stimulsoft.Report.StiReport();

        let companyLogo = new Stimulsoft.Report.Dictionary.StiResource();
        companyLogo.name = 'CompanyLogo'
        companyLogo.alias = 'Company Logo'
        companyLogo.type = Stimulsoft.Report.Dictionary.StiResourceType.Image
        companyLogo.content = Stimulsoft.System.IO.Http.getFile("http://dev.mysite.local/style/default/images/logo.png", true);

        report.dictionary.resources.add(companyLogo)
The above adds the resource to the list:

Image


However when dragging this image into the designer, the image is not showing in preview or when the report is saved and viewed from the viewer.

If I save the report, then reload it, the image in the editor changes to the following as well:

Image

How can I fix this? Is the code I'm using to generate the resource image correct?

Re: Adding Image Resource - Image Not Showing

Posted: Tue Oct 20, 2020 9:18 pm
by Lech Kulikowski
Hello,

Please check that image is available by the url.

Thank you.

Re: Adding Image Resource - Image Not Showing

Posted: Wed Oct 21, 2020 9:08 am
by nickdavies07
The image is available at the path http://dev.mysite.local/style/default/images/logo.png.

When first selecting the variable, it shows the image in the image preview bit. It's only after saving the report definition that it changes to resource://CompanyLogo.

Re: Adding Image Resource - Image Not Showing

Posted: Mon Oct 26, 2020 7:25 am
by HighAley
Hello,

We can't check this. The image is not available for us.
What version of our tool do you use?
Are you sure that the image is available?
Please, check that the image is in PNG format.

Thank you.

Re: Adding Image Resource - Image Not Showing

Posted: Sun Nov 01, 2020 8:46 am
by nickdavies07
OK so I've attached two videos below which explain what happens.

The image is in png format, and as you can see from the first video, it does display in the designer correctly the first time, but not in preview.

Then after the report is reloaded again, it shows it as just the Resource:// link and creates a second variable.

First video is creating-resource.mp4 and second video is reloading-report.mp4

Re: Adding Image Resource - Image Not Showing

Posted: Thu Nov 05, 2020 8:06 am
by Lech Kulikowski
Hello,

Please clarify which version are you use and how do you run the designer?

Thank you.

Re: Adding Image Resource - Image Not Showing

Posted: Thu Nov 05, 2020 9:49 am
by nickdavies07
Hello

So this seems to be working now in the latest update, however when I add my image to the report and then save it and reload, the resource gets added twice?

See images. The resource has the image twice, each time I add the new resource to the report and reload, it gets added again. Any ideas?

Image
Image

Re: Adding Image Resource - Image Not Showing

Posted: Thu Nov 05, 2020 10:29 am
by nickdavies07
Ah I've found the getByName method, so I've done the following if anyone struggles on this later on.

Code: Select all

              if (report.dictionary.resources.getByName('Logo') === null) {
                    let resource = new Stimulsoft.Report.Dictionary.StiResource(
                        "Logo",
                        "Logo",
                        false,
                        Stimulsoft.Report.Dictionary.StiResourceType.Image,
                        Stimulsoft.System.IO.Http.getFile("http://my-image.png", true)
                    );
                    report.dictionary.resources.add(resource)
                }
This will only add when existing resource doesn't exist.

Re: Adding Image Resource - Image Not Showing

Posted: Fri Nov 06, 2020 2:55 pm
by Lech Kulikowski
Hello,

Thank you for the information.