phphtmltagsfpdftext-justify

Justified text with WriteHTML FPDF


Problem: I'm trying make a pdf with FPDF, like this part of a document below (i need a pdf with html tags and Justified text):

Title:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis molestie turpis vitae blandit tristique. Nulla pellentesque et enim non pulvinar. Integer gravida ullamcorper tortor in dignissim. Fusce gravida faucibus ultricies. Morbi pulvinar nibh nec magna tincidunt dignissim. Cras faucibus condimentum pharetra.

Title:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis molestie turpis vitae blandit tristique. Nulla pellentesque et enim non pulvinar. Integer gravida ullamcorper tortor in dignissim. Fusce gravida faucibus ultricies. Morbi pulvinar nibh nec magna tincidunt dignissim. Cras faucibus condimentum pharetra. ....

I can use the tags 'B','P', 'BR' ... or the align justify, but not the two things.

with this two scripts, FPDF Script41 and FPDF Script42 the html tags works fine, but i cant put the align = justify. with this script http://fpdf.de/downloads/addons/8/ i cant use HTML tags, cause he uses "Cell" and "MultiCell".


Solution

  • I had this very same problem and was searching for a solution when I came across your question. Now that I solved it, you can have the solution too :)

    The problem is that Write() calls Cell() and Cell() doesn't support $align='J'.

    I found this solution fpdf addon which adds Justify onto the Cell() function. I compared this code to my Cell() function because the versions are slightly different and used only the relevant parts adding the justify bits.

    Then I followed this function in the FPDF Script42 you mentioned and added an

    $align=''
    

    parameter to the Write() function. Then added it so that it sends that $align through to the Cell call. I'm actually not sure if I added the $align or it was there originally (I made so many changes I can't remember). Then just pass 'FJ' to your Write() call and this will get sent through to tell Cell() to justify.

    $this->Write(5,stripslashes(txtentities($e)),'FJ');