Is there a way to make a piece of text inside a string in bold in nodejs pdfkit?

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

I am using nodejs pdfkit to create pdf. I want bold or italicized individual words in a string. Pdfkit doesn't seem to support this, so I was wondering if anyone had done something like this?

What would be really useful is to call the doc.text function, but save it at position x so that I can 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 result:

some words then italics, then the remaining words.

Now it prints one line per text function.

Does anyone know a good way to do this?

+6
source share
2 answers

See: Is it possible to mix font weight in the same paragraph when using pdfkit?

 pdf.text('Hello ', LEFT, 200, { //here it is, lineBreak : false }).font(bold).text('World!'); 
+6
source

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

It has not yet been integrated with the main project, so I ended up working with pdfkit myself, including changes to ej4s and some of my own.

The main result is that changes allow you to add

 continued: true 

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

+6
source

All Articles