FPDF is not running correctly

I create a PDF file in PHP using the FPDF library, but I can’t get the desired results ie, I can’t write the text in PDF, everything is done correctly, I 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 the code above, I get the following output. enter image description here

What do you think I'm doing wrong?

UPDATE: - As Mr. Rajdep Paul said, I skipped the following line of code.

$pdf->SetFont("Arial","B","10");

I added it to the code and it worked like a charm :)

+4
source share
1 answer

PDF does not display anything because you did not install the font. Set the font as follows:

$pdf->SetFont("Arial","B","10");

Here is the link:

So your code should look 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();

?>
+2
source

Source: https://habr.com/ru/post/1628061/


All Articles