Converting PDF for attaching to email



  • I normal get the link from jsReport to display a PDF in a web page. I now need to take the PDF,or anything else from jsReport, and attach it to an email. I am using the function in the response to convert it to a base64 string. Is there a better way to do this? Is there an option that I could send to jsReport server to give it to me in the format I need?

        client.render(payload, function(err, response) {
            if (err) {
                return deferred.reject({reason:err.message || err})
            }
            response.body(function (body) {
                var pdf = body.toString('base64');          
                return deferred.resolve({data:pdf })
            })
        });

  • administrators

    your code looks fine to me.

    Is there an option that I could send to jsReport server to give it to me in the format I need?

    do you mean an option that jsreport would give you an email response with the report as an attachment? such option does not exists, jsreport response is always a buffer with the content of your report (it can be pdf, html, excel, etc), this gives you a lot of flexibility to embed the report anywhere. so what you are doing in your code looks fine because you are using the buffer as expected.

    of course you also have the option to send the email directly from jsreport in a script (just omit the part of scheduling in the post if you don't need it) if you feel that it is more appropriate for your case. or if you have the need to send this report in other emails it is probably a good idea that you render the report first, store it somewhere and then for your emails you just read the file and add it as attachment separetly.



  • That is what I needed to know. Thanks


Log in to reply
 

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