Page 1 of 2

Load Images into report

Posted: Mon Jul 03, 2017 2:41 pm
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");

Re: Load Images into report

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

Re: Load Images into report

Posted: Tue Jul 04, 2017 11:50 am
by PaPy
Thank you that was exactly what I needed ! Why I did not find this in the Stimulsoft documentation ?

Re: Load Images into report

Posted: Tue Jul 04, 2017 1:37 pm
by Alex K.
Hello

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

Thank you.

Re: Load Images into report

Posted: Tue Jul 04, 2017 2:44 pm
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();
?

Re: Load Images into report

Posted: Wed Jul 05, 2017 7:22 am
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... :?

Re: Load Images into report

Posted: Wed Jul 05, 2017 10:58 pm
by Alex K.
Hello,

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

Thank you.

Re: Load Images into report

Posted: Fri Jul 07, 2017 7:07 am
by PaPy
Thanks for your answer, but I'm not using Jquery. I'm using Polymer.

Re: Load Images into report

Posted: Fri Jul 07, 2017 9:23 am
by Alex K.
Hello,

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

Thank you.

Re: Load Images into report

Posted: Mon Jul 10, 2017 8:32 am
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. :|