Task #1932
Text Align - Justify / Fpdf Advanced Multicell
0%
Description
Hello,
Currently, the alignment justify "J" isn't working well.
My code is:
$pdf = new Pdf();
$multicell = new Multicell($pdf);
$font = "helvetica";
// Set the styles for the advanced multicell
$multicell->setStyle("b", $font, "B", 10, "0,0,0");
$multicell->setStyle("h", $font, "B", 11, "0,0,0");
$multicell->setStyle("p", $font, "", 10, "0,0,0");
$pdf->AddPage();
$pdf->SetMargins(15, 15, 15);
$pdf->SetFont($font, '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFillColor(205, 205, 205);
$pdf->Ln(1);
$multicell->multiCell(0, 10, "CONTRATO DE ARRENDAMENTO PARA FINS HABITACIONAIS COM PRAZO CERTO", 1, "C", 1);
$pdf->Ln(10);
$text = "Espazo Amarelo - Investimento Imobiliário, Unipessoal, Lda., com sede em Av. Infante Santo, n.º 100 A-C, 1350-179 Lisboa, freguesia de Lapa, concelho de Lisboa, NIPC 500111333, aqui representado(a) pelo(a) Manual Santis, na qualidade de Gerente da Sociedade aqui representada, com poderes para o ato, adiante designado(a) de Primeiro(a) Contraente ou Senhorio(a);";
$multicell->multiCell(0, 6, $text, 0, "J");
$pdf->Output();
Files
Updated by Andrei Bintintan about 4 years ago
- Status changed from New to Feedback
- Assignee changed from Andrei Bintintan to Ricardo NC
Please provide the result pdf and the source code as a file(I would like to check the encoding of the file)
Fpdf works only with ISO encoding, if your file is UTF8 encoded that can lead to issues.
In rest, I'll try to execute the use-case myself.
Updated by Andrei Bintintan about 4 years ago
- File examples.zip examples.zip added
I have these results. I'll wait for your feedback.
Updated by Andrei Bintintan about 4 years ago
Updated by Ricardo NC about 4 years ago
Andrei Bintintan wrote in #note-2:
I have these results. I'll wait for your feedback.
Thank you for the quick answer.
The problem was the encoding as you mentioned, but not the encoding of the file.
My script had this line in the top (I forgot to include this line in the example, sorry):
setlocale(LC_ALL, 'pt_PT');
My server has these locale config: LC_CTYPE=pt_PT.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
I think that the utf8 encoding was the issue in comparing strings in the FPDF or multicell library.
I removed the line and everything works fine now.
Thank you for your help.
Updated by Andrei Bintintan about 4 years ago
- Status changed from Feedback to Closed
Keep in mind that this happens if you pass your text from UTF8 files(like in your case - the text is part of the source code).
I generally consider that source code should be UTF8 encoded, but just be careful with the text-encoding in Fpdf.