question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using drawText on a paragraph that uses multiple fonts

See original GitHub issue

Currently 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ahwitzcommented, Oct 2, 2020

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?

0reactions
Hopdingcommented, Oct 2, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Canvas drawText (font) import Times font? - Stack Overflow
I'm trying to use Times as font for the drawText()-method of the Canvas element. However couldn't find a solution yet.
Read more >
Draw with different fonts for the same sentence.
If you wanted to use multiple sprites, you'd have to print out each character one at a time manually changing which font to...
Read more >
How to: Draw Wrapped Text in a Rectangle - Windows Forms ...
To draw wrapped text in a rectangle with GDI+. Use the DrawString overloaded method, passing the text you want, Rectangle or RectangleF, Font...
Read more >
Text in multiple lines · Issue #72 · Hopding/pdf-lib - GitHub
First of all, thanks a lot for this library. I am trying to paint a long and dynamic text that comes from an...
Read more >
Text Handling -- IM v6 Examples - ImageMagick
With multiple images (one for each character) in the font. As they are vector images, it means the font should allow you 'draw'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found