From ed7aa616acbaaa923f2ec5294558a799ad4f1c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Ara=C3=BAjo=20Paes?= Date: Thu, 16 Nov 2023 11:07:46 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Corrigindo=20erros=20de=20encodi?= =?UTF-8?q?ng=20-=20Baseada=20na=20documenta=C3=A7=C3=A3o=20do=20m=C3=A9to?= =?UTF-8?q?do=20`mb=5Fconvert=5Fencoding`=20https://www.php.net/manual/en/?= =?UTF-8?q?function.mb-convert-encoding.php=20se=20o=20terceiro=20parametr?= =?UTF-8?q?o=20for=20omitido=20ser=C3=A1=20utilizada=20`mbstring.internal?= =?UTF-8?q?=5Fencoding=20setting`=20e=20no=20meu=20caso=20n=C3=A3o=20posso?= =?UTF-8?q?=20definir=20ela=20para=20UTF-8=20pois=20meu=20sistema=20est?= =?UTF-8?q?=C3=A1=20todo=20encodificado=20para=20ISO-8859-1.=20Nesse=20cas?= =?UTF-8?q?o=20passei=20um=20array=20com=20dois=20prov=C3=A1veis=20encodin?= =?UTF-8?q?gs=20para=20que=20ele=20possa=20fazer=20a=20convers=C3=A3o=20co?= =?UTF-8?q?rretamente.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Legacy/Pdf.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Legacy/Pdf.php b/src/Legacy/Pdf.php index 4ef5686a..04eaeeca 100644 --- a/src/Legacy/Pdf.php +++ b/src/Legacy/Pdf.php @@ -893,7 +893,7 @@ public function textBox( //remover espaços desnecessários $text = trim($text); //converter o charset para o fpdf - $text = mb_convert_encoding($text, 'ISO-8859-1'); + $text = $this->convertToIso($text); //decodifica os caracteres html no xml $text = html_entity_decode($text); } else { @@ -1034,7 +1034,7 @@ public function textBox90( //remover espaços desnecessários $text = trim($text); //converter o charset para o fpdf - $text = mb_convert_encoding($text, 'ISO-8859-1'); + $text = $this->convertToIso($text); //decodifica os caracteres html no xml $text = html_entity_decode($text); } else { @@ -1117,4 +1117,15 @@ public function textBox90( $this->rotate(0, $x, $y); return ($y1 - $y) - $incY; } + + /** + * Converte os caracteres para ISO-88591. + * + * @param string $text + * @return string + */ + private function convertToIso($text) { + return mb_convert_encoding($text, 'ISO-8859-1', ['UTF-8', 'windows-1252']); + } + }