gofpdf icon indicating copy to clipboard operation
gofpdf copied to clipboard

Justify text with different fonts

Open gpopovic opened this issue 9 years ago • 11 comments

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

gpopovic avatar Oct 29 '15 15:10 gpopovic

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.

jung-kurt avatar Oct 29 '15 17:10 jung-kurt

I will loose my hair calculating width for something like that :)

Any eta for write aligned?

Thanks for great library.

gpopovic avatar Oct 29 '15 17:10 gpopovic

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.

jung-kurt avatar Oct 29 '15 18:10 jung-kurt

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)?

jelmersnoeck avatar Nov 01 '15 10:11 jelmersnoeck

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.

jelmersnoeck avatar Nov 01 '15 14:11 jelmersnoeck

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

hilljc avatar Jan 13 '17 15:01 hilljc

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.

jung-kurt avatar Jan 13 '17 15:01 jung-kurt

Ah, that's a shame. I may have to look into implementing it. Thanks for the reply!

hilljc avatar Jan 13 '17 15:01 hilljc

I do not know PHP, perhaps this is a solution?

http://fpdf.de/downloads/add-ons/forced-justification.html

FrankIT60 avatar Mar 16 '18 11:03 FrankIT60

That solution doesn't seem to support different fonts and attributes.

jung-kurt avatar Mar 16 '18 11:03 jung-kurt

@hilljc117 @jung-kurt have you started this? I'm also interested in justifying text in HTML

mapreal19 avatar Oct 25 '19 10:10 mapreal19