jsreport 4.9.0 is here and brings a new LibreOffice extension and other improvements.
The LibreOffice command line API provides great capabilities for converting or printing Office documents. This API is now wrapped in the custom extension jsreport-libreOffice, which can be additionally installed from npm or used with the jsreport full docker image.
The extension provides studio UI as well as the jsreport scripts API that can be used to trigger converting or printing.
const jsreport = require('jsreport-proxy')
async function afterRender(req, res) {
const pdf = await jsreport.libreOffice.convert(
res.content,
'pdf',
{ pdfExportSelectPdfVersion: 15 }
)
res.content = pdf.content }
Note this extension replaces the jsreport-unoconv extension which si now deprecated and will be removed from the full docker image in v5.
The docxImage
helper now supports passing a custom loader function that loads the image. This is useful when you need more control over how the image is loaded. You may want to use a custom timeout or pass authentication headers.
{{docxImage src=(myImageLoader imageInput)}}
function myImageLoader (src) {
return async function loader () {
const { imageStream, imageType } = await myImageFetchingLogic(src)
return {
type: imageType,
stream: imageStream
}
}
}
A similar approach can be used with the docxHtml
helper as well.
{{docxHtml content=html imageLoader=(myImageLoader)}}
See the documentation for details. https://jsreport.net/learn/docx
The chrome-pdf printing waits for all resources to finish loading. This can be a problem if the report uses external resources like images, where the remote server hangs and the whole report times out. This can now be solved using the new helper chromeResourceWithTimeout
.
<img src="{{{chromeResourceWithTimeout 'http://myImageUrl.png}}}' 2000}}"/>
The helper makes sure the resource loading gets canceled after the timeout. The resource won't be loaded, but the whole report passes.
The Chrome printing is typically the HW resources bottleneck. If this is the problem, there is an option to connect remote Chrome instances to jsreport. This can be done using the following config.
{
"chrome": {
"strategy": "connect",
"connectOptions": {
"browserWSEndpoint": "<endpoint to the remote instance of Chrome>"
}
}
}