Using drawText on a paragraph that uses multiple fonts
See original GitHub issueCurrently trying to transpile a bunch of code that used reportlab/FPDF in Python into JS. This library is significantly more straightforward to use, but I’ve run into one problem that I can’t find a solution for yet.
I need to embed a citation that uses the following syntax:
Author, Author, Author. Title of article. Title of containing journal. Additional metadata at the end.
I’ve got maxWidth, multiple fonts, and manual typesetting down. My question is how I could get the “Additional metadata” bit at the end to line-break automatically, because I have to create a separate block of text with the italics. Could make this work with a textIndent option on drawText or something like that.
Is there a way to do multiple fonts in a single paragraph, and/or is there a way to set the indent of the first line of a block of text?
Thanks for any answers/help you can provide!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
I’m definitely not realizing something you are: what primitives exist to allow the green box to be positioned dynamically after the blue box? Or, at least, how can I know where the line break around “extravagantly long word” will be positioned, or how much extra space will be left on the line before?
@ahwitz That makes sense. It would be nice if pdf-lib provided text layout information to facilitate more complicated use cases like this. However, since the necessary primitives already exist, I will not personally be creating these APIs for some time. There are a number of other features I need to implement first. So I’m going to close this issue for now. That being said, I’m happy to accept PRs if anybody would like to work on this.