Using HTML Canvas in docx recipe



  • Hi All,

    My team already has template to generate report using docx recipe. It's working fine until I've been assigned to a task where a client asked to include thermal images for their report.

    We have functions to decode raw thermal images from backend as an array buffer. We successfully render thermal images in our web app using HTML Canvas API, CanvasRenderingContext2D.createImageData(). And now I am wondering how to render the decoded thermal images to docx recipe. Can I use HTML canvas inside docx recipe? So I can use createImageData() like I did in web app.

    This is list of packages we use

    • handlebars-intl
    • handlebars-helpers
    • pdf-lib
    • bluebird
    • lodash
    • mathjs
    • jimp
    • moment-timezone
    • axios
    • jpeg-js
    • protobufjs
    • tinygradient

    Note: I am new to jsreport
    Thanks



  • Not sure if the Word supports canvas images natively.
    Anyway, the recipe now supports just png and jpeg images.

    What you need to do is convert the canvas to the png.
    This can be done on your client-side, or by implementing a custom jsreport templating engine helper.

    Here you can find an example of how the image can be resized using a custom helper
    https://jsreport.net/learn/templating-engines#async

    Your solution will be similar, you just need to use an extra package that can convert canvas into png. Like this one
    https://github.com/Automattic/node-canvas



  • Thanks for your suggestion, It's done using node-canvas.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.