我正在使用 Node.js 和 Angular 构建一个 Web 应用程序,我希望生成一个可供客户端下载的 PDF。我目前正在使用 phantomjs 下载 PDF 文件。我如何使用 Node.js Express 应用程序实现此目的?
最佳答案
fs.readFile('/temp/example.pdf',function(error,data){
if(error){
res.json({'status':'error',msg:err});
}else{
res.writeHead(200, {"Content-Type": "application/pdf"});
res.write(data);
res.end();
}
});
或者
res.download('/temp/example.pdf');
关于node.js - 如何使用node.js 和express 生成和下载PDF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29952933/