我正在尝试使 jsreport 在 Azure Function 应用程序中工作。我已经安装了所有需要的包,它们是 jsreport-core jsreport-render jsreport-phantom-js,它们似乎都工作得很好。我的代码:
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (req.query.content || (req.body && req.body.content)) {
var pdf = renderPdf(req.query.content || req.body.content, {})
context.res = {
status: 200,
body: { data: pdf }
};
}
else {
context.res = {
status: 400,
body: "Please pass the content on the query string or in the request body"
};
}
context.done();};
function renderPdf(content, data){
var jsreport = require('jsreport-core')();
var promise = jsreport.init().then(function () {
return jsreport.render({
template: {
content: content,
engine: 'jsrender',
recipe: 'phantom-pdf'
},
data: data
});
});
return Promise.resolve(promise);}
我以这篇文章为例:Export html to pdf in ASP.NET Core
我的最终目标是从 asp.net 核心调用这个函数。谢谢您的帮助。