0

I make a PDF file from PHP. I use FPDF library. I don't have polish letters in result PDF. This is my code:

    $pdf = new FPDF();
$pdf->AddPage();
$pdf->AddFont('helvetica','',TEMPLATEPATH.'/fonts/helvetica.php');
$pdf->SetFont('helvetica','');
$text = 'WITAJ ŻÓŁĘDZIU';
$pdf->Write(5,$text);

I use this code (I tried to use iconv but it didn't work). My result is: "Witaj ¿ó³êdziu". What should I do?

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
patwoj98
  • 449
  • 2
  • 16
  • 1
    The fact that you see `¿ó³ê` proves that you have an encoding problem. `ŻÓŁ` are characters in CP1250 encoding, whereas `¿ó³ê` are the representation of the same characters in another encoding. – Bruno Lowagie Nov 28 '15 at 11:32
  • 1
    Read http://stackoverflow.com/q/26631815/2564301 for technical reasons why this won't work "out of the box" (it probably won't offer a solution, but at least tell you why). – Jongware Nov 28 '15 at 13:25
  • 1
    Possible duplicate of [FPDF utf-8 encoding (HOW-TO)](http://stackoverflow.com/questions/6334134/fpdf-utf-8-encoding-how-to) – Lucas Trzesniewski Nov 29 '15 at 11:05

2 Answers2

1

Does your PHP script uses UTF-8 ? FPDF does not natively handle UTF-8, that may explains why you get weird characters.

You can use TCPDF (http://www.tcpdf.org) which handles perfectly UTF-8. The migration from FPDF to TCPDF is quite easy since it uses the same methods (same methods names, same arguments) as FPDF.

Levure
  • 335
  • 1
  • 4
  • 16
0

Have you tried UTF-8 encoding $text?

Set your second last line of code to:

$text = utf8_encode('WITAJ ŻÓŁĘDZIU');
Jesse
  • 76
  • 1
  • 9