Juned Ansari
Juned Ansari

Reputation: 5283

fpdf outputs garbage values

I am Trying to Generate PDF output into string but it generates garbage output.

<?php
//here some code will come 
require('fpdf.php'); 
$pdf =new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('file.pdf','D');
?>

FPDF works fine when i use simply example code but when i use same code into my project it returns garbage values like

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T04�30PISp    �Z*�[����(hx����+���(j*�d��7W endstream endobj 1 0 obj <> endobj 5 0 obj <> stream x�]R�n�0��>��L�%�DI�8���~�%E*r�ﻻvҪHX�gvVk?/���Ῑ��`]�[�x5 �3\z��P�}����PO���j�Jݍ^���x6/f�����������|���4}�z�����}���@�,ۖ-��˺E�u�^�,���<� �Z_�K� IQ����Yd����C�K�_�%q�8>�!J"V!2&bGģ%r"H��D��\}2EL1n��h�j���e��"a*H����:��d��9c���[�X1~��"�3�g��Ñ�;O��> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 6 0 R >> /XObject << >> >> endobj 7 0 obj << /Producer (FPDF 1.81) /CreationDate (D:20170323090213) >> endobj 8 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 9 0000000000 65535 f 0000000228 00000 n 0000000867 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000749 00000 n 0000000971 00000 n 0000001047 00000 n trailer << /Size 9 /Root 8 0 R /Info 7 0 R >> startxref 1096 %%EOF

Upvotes: 0

Views: 1104

Answers (2)

Ali Parsa
Ali Parsa

Reputation: 131

You must convert used fonts here. After that move converted files to the /fonts directory.

Upvotes: 0

ashish bansal
ashish bansal

Reputation: 411

please check your character set encoding if they are supporting or not. rather follow this link to read more about fpdf offcial page. FAQ

Don't use UTF-8 with the standard fonts; they expect text encoded in ISO-8859-1 or windows-1252. You can use utf8_decode() to perform a conversion to ISO-8859-1:

 $str = utf8_decode($str);

But some characters such as Euro won't be translated correctly. If the iconv extension is available, the right way to do it is the following:

 $str = iconv('UTF-8', 'windows-1252', $str);

Upvotes: 1

Related Questions