Page 1 of 1

Error Loading image in header

Posted: Sat May 18, 2019 5:53 am
by a.delbrocco@swen.it
Hi i need to load an external image in header.
I use js from node.
I have tried different way to do it.
with image variable, and with json datasource.
In designer preview mode is ok, when i export to pdf no image is inside.

Code: Select all

const Stimulsoft = require("stimulsoft-reports-js");
const report = new Stimulsoft.Report.StiReport();

/* if i not set a font the report is outputted as a garbage font (the font is standard arial) */
Stimulsoft.Base.StiFontCollection.addOpentypeFontFile(reportPath + "/reports/Roboto-Black.ttf");

/*load report*/
report.loadFile(reportPath + "/reports/TestReport.mrt");

/* try to setting image into variable*/
const image = Stimulsoft.Base.Drawing.StiImageConverter.stringToImage(associazione.blobImage);
report.dictionary.variables.getByName("imageHeader").valueObject = image;

/*try to use datasource */


/*
var dbsimpleImage = report.dictionary.databases.getByName("simpleImage");
dbsimpleImage.pathData = "C:\\Progetti\\arco\\arco-api.v2\\uploads\\reports\\simpleImage.json";
*/

const dssimpleImage = new Stimulsoft.System.Data.DataSet();
dssimpleImage.readJsonFile("simpleImage.json");
report.regData("simpleImage", null, dssimpleImage);

// Renreding report
			report.render();
			console.log("Report rendered. Pages count: ", report.renderedPages.count);

			const pdfData = report.exportDocument(Stimulsoft.Report.StiExportFormat.Pdf);
			// Converting Array into buffer
			const buffer = Buffer.from(pdfData);
			// File System module
			const fs = require("fs");
			// Saving string with rendered report in PDF into a file
			fs.writeFileSync(generatedFileName, buffer);

I attach a very simple test.
Report
json
pdf outputted

Re: Error Loading image in header

Posted: Mon May 20, 2019 11:52 am
by Lech Kulikowski
Hello,

Please try to use async methods to render and export report with images:

Code: Select all

var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/test.mrt");
report.render();
var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
// Create an PDF service instance.             
var service = new Stimulsoft.Report.Export.StiPdfExportService();
// Create a MemoryStream object.             
var stream = new Stimulsoft.System.IO.MemoryStream();
// Export PDF using MemoryStream.             
service.exportToAsync(function () {                 
    var data = stream.toArray();                 
    // Get report file name                 
    var fileName = String.isNullOrEmpty(report.reportAlias) ? report.reportName : report.reportAlias;         
    // Save data to file                 
    Object.saveAs(data, fileName + ".pdf", "application/pdf");
}, report, stream, settings);
Thank you.

Re: Error Loading image in header

Posted: Thu May 23, 2019 4:00 pm
by a.delbrocco@swen.it
Ok i'll try, but in my service i need to wait for report completion in sync to accomplish other tasks.
For example i have to return report content in rest return data

Re: Error Loading image in header

Posted: Mon May 27, 2019 6:22 am
by Lech Kulikowski
Hello,

Ok. Please let us know about the result.

Thank you.