3

I installed pdfkit and now I am trying to add text to pdf and save it to disk. I am following tutorial from http://blog.nodeknockout.com/post/9134350698/countdown-to-ko-8-introduction-to-pdfkit but I keep getting an error below. How can I add a text using node.js and pdfkit?

thank you. source code:

 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');

error

/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)

1 Answer 1

2

It should be doc.text since you have other lines of code between the .fill call and .text, creating a syntax error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.