7

Node-pdfkit http://pdfkit.org/index.html

I am using nodejs pdfkit to generate a pdf. I want to be able to bold or italic individual words in a line. It looks like pdfkit doesn't support this, so I was wondering if anyone had done something similar?

What would be really useful is to call the doc.text function, but have the document retain it's x position, so that I could do the following.

doc.text('some words then ');
doc.font('Helvetica-Oblique');
doc.text('italic');
doc.font('Helvetica');
doc.text(' then the remaining words');

and see the output:

some words then italic then the remaining words.

Right now it's outputting one line per text function.

Anyone know a good way to do this?

Mark Withers
  • 1,462
  • 5
  • 16
  • 34
  • Related: http://stackoverflow.com/questions/20598693/can-i-mix-font-weights-in-the-same-paragraph-when-using-pdfkit – m90 Dec 27 '13 at 11:51

2 Answers2

12

This feature was added by ej4 in this pull request https://github.com/devongovett/pdfkit/pull/60

It hasn't been merged in to the main project yet, so I ended up forking pdfkit myself, and including ej4s changes and a few of my own.

The basic result is that the changes make it possible to add

continued: true

to the options object. Pdfkit then remembers the caret position and returns you to that position for the next line of text.

Mark Withers
  • 1,462
  • 5
  • 16
  • 34
10

Please see: Can I mix font weights in the same paragraph when using pdfkit?

pdf.text('Hello ', LEFT, 200, {
    //here it is, 
    lineBreak : false
}).font(bold).text('World!');
Community
  • 1
  • 1
zag2art
  • 4,869
  • 1
  • 29
  • 39