我安装了 pdfkit,现在我正在尝试将文本添加到 pdf 并将其保存到磁盘。我正在关注来自http://blog.nodeknockout.com/post/9134350698/countdown-to-ko-8-introduction-to-pdfkit的教程,但我一直在下面收到错误消息。如何使用 node.js 和 pdfkit 添加文本?
谢谢你。源代码:
doc = new PDFDocument();
doc.moveTo(300, 75)
.lineTo(373, 301)
.lineTo(181, 161)
.lineTo(419, 161)
.lineTo(227, 301)
.fill('red', 'even-odd');
var loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in...';
doc.y = 320;
doc.fillColor('black')
.text(loremIpsum, {
paragraphGap: 10,
indent: 20,
align: 'justify',
columns: 2
});
doc.write('out.pdf');
错误
/Users/sadmin/Dropbox/Node JS/wordlets/wordCloud.js:61
.text(loremIpsum, {
^
TypeError: Property 'text' of object [object PDFDocument] is not a function
at Object.createPDF (/Users/sadmin/Dropbox/Node JS/wordlets/wordCloud.js:61:5)
at /Users/sadmin/Dropbox/Node JS/wordlets/requestHandlers.js:62:15
at Request._callback (/Users/sadmin/Dropbox/Node JS/wordlets/wordCloud.js:116:5)
at Request.init.self.callback (/Users/sadmin/node_modules/request/main.js:122:22)
at Request.EventEmitter.emit (events.js:99:17)
at Request.<anonymous> (/Users/sadmin/node_modules/request/main.js:661:16)
at Request.EventEmitter.emit (events.js:126:20)
at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (/Users/sadmin/node_modules/request/main.js:623:14)
at IncomingMessage.EventEmitter.emit (events.js:126:20)
at IncomingMessage._emitEnd (http.js:366:10)