如何在Node JS中创建PDF文件 [英] How to create pdf file in node js

查看:256
本文介绍了如何在Node JS中创建PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sails框架在node.js中创建一个应用程序.我想创建PDF格式的报告.该报告需要包含使用chart.js生成的图表.从mongodb获取数据,并显示在canvas上.如何使用node.js创建此图表的PDF文件?

I am creating an application in node.js utilizing the sails framework. I want to create a report in PDF format. The report needs to contain a chart generated using chart.js. The data is fetched from mongodb and displayed on a canvas. How can I create a PDF file of this chart using node.js?

推荐答案

PDFKit .

安装:

npm install pdfkit

示例:

var PDFDocument = require('pdfkit');

doc = new PDFDocument;    
doc.pipe(fs.createWriteStream('output.pdf'));    
doc.font('fonts/PalatinoBold.ttf').fontSize(25).text(100, 100);

这篇关于如何在Node JS中创建PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆