php fpdf simple file is not working

4k Views Asked by At

I have a simple app where the php file updates the database then it generates a pdf file and stores in local folder. below is the code. the pdf file is getting generated and working fine. but am not able to add text into it. when i insert image its working. but inserting cell or text is not working. i dont know whats gone wrong.. pl;z help me.. thanks

$pdf = new FPDF();
$pdf->AddPage();
// $pdf->Image('images/logo.png',90,15,90,0,'PNG');

$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');


$pdf->Output("pdffiles/testsuccess.pdf",'F');
2

There are 2 best solutions below

0
On

Finally, I found it.. weird but it will be very useful for the developers who is new to fpdf... I have mentioned that image is working and only text is not working.. Means you should include the fonts folder which comes with fpdf when downloading. If fonts folder is missing it does not print any text..

Thank you

1
On

When I test your code it works fine for me. The only thing I DON'T see in your code is the require statement for the fpdf.php file.

heres the FULL php file contents for the example that works for me:

<?php

    require('fpdf/fpdf.php');  // MAKE SURE YOU HAVE THIS LINE

    $pdf = new FPDF();
    $pdf->AddPage();

    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');

    $pdf->Output("testsuccess.pdf",'F');
?>