i am creating a PDF in PHP using FPDF library, but i am unable to get my desired results i-e i am unable to write text to PDF every other thing is done correctly , i have used both methods
$pdf->SetXY();
$pdf->Write(0,"Some Text");
and
$pdf->Text(10,10, "Some other Text");
here is my full code
<?php
include_once "fpdf/fpdf.php";
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetLineWidth(0.5);
$pdf->Text(10, 10, "Test Data");
$pdf->Line(10, 15, 200, 15);
$pdf->Line(10, 280, 200, 280);
$pdf->Line(10, 15, 10, 280);
$pdf->Line(200, 15, 200, 280);
$pdf->Rect(10, 15, 190, 15);
$pdf->SetXY(30, 30);
$pdf->Write(10, 'Text1');
$pdf->Output();
?>
Using above code i am getting following output.
What do you think i am doing wrong?
UPDATE :-- As Mr. Rajdeep Paul suggested i was missing following line of code.
$pdf->SetFont("Arial","B","10");
i added it in the code and it worked like a charm :)
The PDF is not displaying anything because you didn't set the font. Set font like this:
$pdf->SetFont("Arial","B","10");
Here's the reference:
So your code should be like this:
<?php
include_once "fpdf/fpdf.php";
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B","10");
$pdf->SetLineWidth(0.5);
$pdf->Text(10, 10, "Test Data");
$pdf->Line(10, 15, 200, 15);
$pdf->Line(10, 280, 200, 280);
$pdf->Line(10, 15, 10, 280);
$pdf->Line(200, 15, 200, 280);
$pdf->Rect(10, 15, 190, 15);
$pdf->SetXY(30, 30);
$pdf->Write(10, 'Text1');
$pdf->Output();
?>