Error while trying to load an image to a report
-
Hello,
I'm using jsreport with node, and I'm trying to show load a jsreport on PDF format with an image on it. Here are the code I'm writing:
let clientLogoPath = path.join(__dirname, "../public/images/temp/client_logo.jpg");
jsreport.init().then(() => {jsreport.render({ template: { content: `<h1 class="report-title">Report</h1><img src="{{asset "${clientLogoPath}" "dataURI"}}" />`, engine: 'handlebars', recipe: 'chrome-pdf' }, }).then((out) => { out.stream.pipe(res); }).catch((e) => { res.end(e.message); }); }).catch((e) => { console.error(e.stack) process.exit(1)})
When I try to Run the following error occur:
Error when evaluating engine handlebars for template anonymous
Asset "Full Path image) not found.I'm just starting with jsreport, can anyone please guide me through?
-
hi @brunomanguinho, assets by default search in the jsreport store, if you want to read a file from the filesystem you need to enable the external file access, add this to your jsreport options (either your configuration file or the options you pass when calling
jsreport({ /* options here */ })
:{ extensions: { assets: { allowedFiles: "**/*.*", searchOnDiskIfNotFoundInStore: true } } }
after it the assets will be allowed to read from the filesystem and will find your image.