Load Images into report

Stimulsoft Reports.JS discussion
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Load Images into report

Post by PaPy »

Hi,

I try to load a simple image on my report. I have a folder on my side which contains some images. I want to load an image on my report thanks to an url.
For example I want to do something like :

Code: Select all

report.addImageInResources("/Images/myImage.png");
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Load Images into report

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

var content = Stimulsoft.System.IO.Http.getFile("url", true);
var resource = new Stimulsoft.Report.Dictionary.StiResource("ImgName", "ImgAlias", false, Stimulsoft.Report.Dictionary.StiResourceType.Image, content);
report.dictionary.resources.add(resource);
Thank you.
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Load Images into report

Post by PaPy »

Thank you that was exactly what I needed ! Why I did not find this in the Stimulsoft documentation ?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Load Images into report

Post by Alex K. »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Load Images into report

Post by PaPy »

When I save the report with my image and I reopen my report, I can't see the image.

Here is what I get the first time (see in attachment FirstTimeOpen screenshots)
Then, I save the report.
But when I reopen this report I don't see the image that I added. Here is what I get in the second time (see in attachment SecondTimeOpen screenshots)

Here is the code used to generateTheReport :

Code: Select all

  generateReport: function() {
        // License
        Stimulsoft.Base.StiLicense.loadFromFile(LICENCE_PATH);
        // Définit l'interface par défaut en Français
        Stimulsoft.Base.Localization.StiLocalization.addLocalizationFile(LOCALIZATION_PATH + "fr.xml", true, "French (Français)");
        // Ajout de Espagnol dans le menu de choix de langues.
        Stimulsoft.Base.Localization.StiLocalization.addLocalizationFile(LOCALIZATION_PATH + "es.xml", false, "Spanish (Español)");

        report = new Stimulsoft.Report.StiReport();
        // Initialise la source de données.
        var dataSet = new Stimulsoft.System.Data.DataSet("Données");

        report.load(this.mrt);

        // On vide le dictionary du mrt pour partir sur quelque chose de propre.
        report.dictionary.clear();

        //console.log(report);
        //report.dictionary.resources.add("/src/report/Images/sol_logo.jpg");

        // Ajout des données au report.
        var listDatas = JSON.parse(this.datas);
        for (var i in listDatas){
          // Lecture d'une table dans le JSON.
          dataSet.readJson(listDatas[i]);
          // Association table / Source de données.
          report.regData(dataSet.dataSetName, "", dataSet);
        }

        //dataSet.readJson("");
        //report.regData(dataSet.dataSetName, "", dataSet);

        // Synchronisation du dictionary avec ses nouvelles données.
        report.dictionary.synchronize();

        // Ajout des alias aux colonnes.
        this.setAliasOnReport(report);


        // How can I clean the report.dictionary.resources as I do for datas ?
        //report.dictionary.resources = [];

        var content = Stimulsoft.System.IO.Http.getFile("/src/report/Images/sol_logo.png", true);
        var resource = new Stimulsoft.Report.Dictionary.StiResource("ImgName", "ImgAlias", false, Stimulsoft.Report.Dictionary.StiResourceType.Image, content);
        console.log(report.dictionary.resources);
        report.dictionary.resources.add(resource);
        report.dictionary.synchronize();

        // Nécessaire de le rendre une fois que tout est prêt pour l'afficher.
        report.render();

        // Créer le viewer.
        this.createViewer();
      }
Is there a way to clean the report.dictionary.resource ? I already do a report.dictionary.clear() but it don't seems to work for the resources...
Or is there a way to know if my file already exist ?
Moreover, in the future I want to offer all files in my folder "/src/report/Images", is there something to do something like

Code: Select all

var contents = Stimulsoft.System.IO.Http.getFiles("/src/report/Images/*", true);
contents.forEach(function (c) {
    var resource = new Stimulsoft.Report.Dictionary.StiResource("ImgName", "ImgAlias", false, Stimulsoft.Report.Dictionary.StiResourceType.Image, c);
    report.dictionary.resources.add(resource);
});
report.dictionary.synchronize();
?
Attachments
SecondTimeOpen Designer
SecondTimeOpen Designer
SecondTimeOpen_Designer.PNG (145.18 KiB) Viewed 7503 times
SecondTimeOpen Viewer
SecondTimeOpen Viewer
SecondTimeOpen_Viewer.PNG (18.58 KiB) Viewed 7503 times
FirstTimeOpen Designer
FirstTimeOpen Designer
designFirstTimeOpen.PNG (121.37 KiB) Viewed 7503 times
FirstTimeOpen Viewer
FirstTimeOpen Viewer
firstTimeOpen.PNG (23.27 KiB) Viewed 7503 times
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Load Images into report

Post by PaPy »

For the moment I added a control for one image. It will change for more than one. But I still do not know how I can import all images in a folder... :?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Load Images into report

Post by Alex K. »

Hello,

You can find several solutions at the following link:
https://stackoverflow.com/questions/184 ... ing-jquery

Thank you.
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Load Images into report

Post by PaPy »

Thanks for your answer, but I'm not using Jquery. I'm using Polymer.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Load Images into report

Post by Alex K. »

Hello,

Please try to find some information in the documentation of the Polymer library.

Thank you.
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Load Images into report

Post by PaPy »

Hi,

I found a better way to do what I wanted to do. but I would like to add my image to Dictionary -> DataSources -> myCompanyInformation in a column "logo". I already try to create this column with an url (to the image) value but when I drag-and-drop the column I see the url text and not the image.

Is there a way to print this image only using the url ? I do not want to use base64... i simply want that my user got a column which contains an image and just have to drag-and-drop this column to see the image. :|
Post Reply