gofpdf
gofpdf copied to clipboard
Justify text with different fonts
I'm having problem justfying text with different fonts (some parts of text are bold, some are not)..
Is this possible? :/
Justification with a single font is not a problem
This problem is currently being worked on with the WriteAligned() method. When that gets ironed out, you will be able to align text using basic HTML with italic and bold tags. In the mean time, you can use GetStringWidth() to calculate segments of text, each with a different font attribute.
I will loose my hair calculating width for something like that :)
Any eta for write aligned?
Thanks for great library.
I will loose my hair calculating width for something like that :)
I hear you! You would definitely want to generalize the procedure with a helper routine, for example, one that would accept an array of substrings with the appropriate attribute.
Any eta for write aligned?
Not sure. It is an open issue and @jelmersnoeck is working on it, so a fix should not take too long.
I'm not entirely sure this is exactly the same. With justification you space out the word blocks as well, which is not possible at all so far (or not that I know of).
The open issue mentioned is aligning HTML text properly (Left/Center/Right). I haven't had the time to look into this further yet, but hope to do this soon.
@gpopovic do you have an example of what exactly you mean? Is it only alignment or is it stretching sentences as well (by entering spaces)?
Digging into the code a bit more, seems like MultiCell
does the justification already indeed, but this doesn't handle HTML tags.
The issue mentioned might help towards solving that, but there'll be some extra work to make justification work for HTML.
I'm looking to have a paragraph with parts of it bold, but I can't seem to find a way to do this AND have the entire paragraph be justified. Right now i'm using MultiCell() up until I need to write bold text and then using Write() for that. However, the last line that gets printed by MultiCell() is not justified. Is there a method that supports this? Thanks in advance
Unfortunately, this is not supported yet. The approach we will probably take is to extend the Write method of an HTML block to support justified text. If you want to tackle that, take a look at the HTML Write method.
Ah, that's a shame. I may have to look into implementing it. Thanks for the reply!
I do not know PHP, perhaps this is a solution?
http://fpdf.de/downloads/add-ons/forced-justification.html
That solution doesn't seem to support different fonts and attributes.
@hilljc117 @jung-kurt have you started this? I'm also interested in justifying text in HTML