-
-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using drawText on a paragraph that uses multiple fonts #577
Comments
I spent a bit of time trying to write a PR for this, and got stuck in one of two places:
|
Hello @ahwitz!
|
We've actually gone a slightly different direction internally for what we're looking for, but the problem is that we want to write roman text THEN italicized text THEN roman text again in the same paragraph. My implementation right now is something along the lines of:
This works, but only if we know the exact width of previous lines in advance. Because these citations can stretch across multiple lines in a single paragraph (and because the "title of containing journal" might be rather long), and because we're using Does that make sense? I can try to mock up a few PDFs if it's not clear. |
I think that makes sense. So what you're after is a way to know what bounding box (x,y,width,height) contains the text applied to the page by |
Unfortunately, no. I've actually built that on top already without touching the base code, and that was relatively straightforward. For more clarity: The vertical bounding box components for the blue text would be two lines. The horizontal bounding box components would be 0 to wherever the line break was inserted. Given the current API, to position the green text, we would need to know specifically where the blue text ended on the third line, so that we could start the green text at the proper kerning/spacing from it. I think something like |
@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. |
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? |
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:
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 atextIndent
option ondrawText
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!
The text was updated successfully, but these errors were encountered: