Adding Image Resource - Image Not Showing

Stimulsoft Reports.JS discussion
Post Reply
nickdavies07
Posts: 28
Joined: Fri Jul 17, 2020 2:19 pm

Adding Image Resource - Image Not Showing

Post 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?
Lech Kulikowski
Posts: 7354
Joined: Tue Mar 20, 2018 5:34 am

Re: Adding Image Resource - Image Not Showing

Post by Lech Kulikowski »

Hello,

Please check that image is available by the url.

Thank you.
nickdavies07
Posts: 28
Joined: Fri Jul 17, 2020 2:19 pm

Re: Adding Image Resource - Image Not Showing

Post 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.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Adding Image Resource - Image Not Showing

Post 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.
nickdavies07
Posts: 28
Joined: Fri Jul 17, 2020 2:19 pm

Re: Adding Image Resource - Image Not Showing

Post 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
Attachments
reloading-report.mp4
(470.69 KiB) Downloaded 468 times
creating-resource.mp4
(548.44 KiB) Downloaded 431 times
Lech Kulikowski
Posts: 7354
Joined: Tue Mar 20, 2018 5:34 am

Re: Adding Image Resource - Image Not Showing

Post by Lech Kulikowski »

Hello,

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

Thank you.
nickdavies07
Posts: 28
Joined: Fri Jul 17, 2020 2:19 pm

Re: Adding Image Resource - Image Not Showing

Post 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
nickdavies07
Posts: 28
Joined: Fri Jul 17, 2020 2:19 pm

Re: Adding Image Resource - Image Not Showing

Post 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.
Lech Kulikowski
Posts: 7354
Joined: Tue Mar 20, 2018 5:34 am

Re: Adding Image Resource - Image Not Showing

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply