使用.net Web API在服务器端生成包含部分HTML内容的PDF

问题描述 投票:0回答:1

我们的应用程序前端是有角度的,后端是.net Web API我们要为用户使用的所有产品生成pdf报告。这里的产品描述是HTML内容,因此我们需要一种在服务器端将HTML内容和产品信息呈现为pdf的方法。

现在,我们正在使用“活动报告”部分的报告来生成不带说明的pdf,因为在活动报告中,RichText仅支持最低级别的HTML标签,因此我们需要更多。因此,我们需要一种更好的解决方案来在服务器端生成带有HTML内容的pdf。

c# html pdf activereports webapi
1个回答
0
投票

您可以使用html-pdf模块将html转换为pdf。它提供了大量将html转换为pdf的方法。以下是其中一些:

let pdf = require('html-pdf');
pdf.create(html).toFile([filepath, ]function(err, res){
  console.log(res.filename);
});

pdf.create(html).toStream(function(err, stream){
  stream.pipe(fs.createWriteStream('./foo.pdf'));
});

pdf.create(html).toBuffer(function(err, buffer){
  console.log('This is a buffer:', Buffer.isBuffer(buffer));
});

它还允许您定义options以自定义页面。

© www.soinside.com 2019 - 2024. All rights reserved.