Problem with text recipe encoding



  • Hello, thanks for the help in advance. I'm using the text recipe to generate plain text file that contains bills. The problem is that the encoding is UTF-8 all the time. In "Content Type" I changed to "text/plain; charset=windows-1252" but it still download the file in UTF-8 and we really need it in windows-1252. Is there anything else I have to do? Thanks again.


  • administrators

    hello! we currently only support UTF8 encoding, you can change the Content Type header (as you are already doing) with your desired charset but the content will be still encoded as UTF8.. supporting more encodings will take some time so your best options right now is to do one of the following:

    • you can perform your own conversion using handlebars/jsrender/jade directly on your own and save the result in your desired encoding.
    • continue using jsreport to generate the text file, but you will need the convert the file from UTF8 -> to windows-1252 in your backend.


  • Ok, thanks for the help!



  • It turned out this is already possible with current version. You just need to create custom jsreport script and in the afterRender hook encode the result into desired encoding. For example for windows-1252 you can do.

    const iconv = require('iconv-lite');
    function afterRender(req, res) {
      res.content = Buffer.from(iconv.encode(res.content.toString(), 'win1252'), 'binary')
    }
    

Log in to reply
 

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