Error Loading image in header

Stimulsoft Reports.JS discussion
Post Reply
a.delbrocco@swen.it
Posts: 4
Joined: Sat May 18, 2019 5:17 am

Error Loading image in header

Post 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
Attachments
simpleImage.json
simplejson
(51.95 KiB) Downloaded 138 times
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Error Loading image in header

Post 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.
a.delbrocco@swen.it
Posts: 4
Joined: Sat May 18, 2019 5:17 am

Re: Error Loading image in header

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

Re: Error Loading image in header

Post by Lech Kulikowski »

Hello,

Ok. Please let us know about the result.

Thank you.
Post Reply