PHP & FPDF: Calculating justified text width -


Then I am using PPDF in PHP so that the PDF file can be generated from images and text (not HTML) .

The biggest problems I am putting in will rotate the text around an image. My current algorithm looks like this:

  1. Get the text as an array of words
  2. Add the word to a 'current line' variable once, and getStringWidth () Call it to set the width of this current line
  3. Once I reach a predetermined maximum width, I pass an existing line to an array of lines, and a new 'current line I start with

By doing this, I get permission to get an array of lines that should not be broken incorrectly, although I have found that my text is justified because GetStringWidth does not give me right Could the width of the line when it became fair.

I have tried to use the FPDF's multi-dimensional method and to understand how it corrects the proper text but can not really do it head and not The tail itself seems to boil the same algorithm (and it writes every line using the cell ), but it does not actually calculate the width, this is the "code" Such as 0.375 Tw .

Do anyone know how to calculate the width of the appropriate text depending on the string and maximum width?

Really answer the old question.

Finally, I took the function that receives justification from the library and rewrites it to allow a second parameter which continues it

The result is the text Which was perfectly appropriate for a specific paragraph, then you write the last paragraph without parameters and the last line is not appropriate (in general).


Comments