Undefined font: In Fpdf
Asked Answered
E

4

9

I'm New to Fpdf library, i need to create a pdf from data base in smarty. i have checked the data from data base is fine, when pass the font name the below error was show

Warning: in_array() expects parameter 2 to be array, null given in /var/www/html/irmt/library/class/fpdf/fpdf.php on line 526
<b>FPDF error:</b> Undefined font: helvetica B

my code is

            $pdf->AddPage();
            $pdf->SetFont('Arial','B',14);
            $pdf->FancyTable($result);
            $pdf->Output();

Please help me how can i solve this problem. thank adv

Eckhart answered 4/1, 2013 at 5:1 Comment(0)
D
24

I think your __construct in the pdf creation is problem, try this one in

    require_once("fpdf.php");
    class pdf extends FPDF
    {
      function __construct()
       {
          parent::FPDF();
       }
    }
Diptych answered 7/1, 2013 at 7:12 Comment(1)
Good one. That one really worked it for me. To add on this, it might be even more preferred to pass several parameters to the constructor and then to the FPDF class eg orientation etc. That is what i had to do for my page to be with landscape orientation: function __construct($orientation, $units, $size) { parent::FPDF($orientation, $units, $size); }Olds
O
4

that's because you call the constructor of the fpdf library, change the fpdf library function (parameters) to __ construct (parameters), then spread it from your file. example: file : genpdf.php

<?php 
include('fpdf.php');
class Genpdf extends Fpdf{
    public function __construct()
    {
       parent::__construct();
    }
    public function build()
    {
       $this->AddPage();
       $this->SetFont('Arial','B',16);
       $this->Cell(40,10,'¡Hola, Mundo!');
       $this->Output();
    }
}
Orthogenesis answered 13/11, 2013 at 1:36 Comment(0)
S
1

Try to remove the line $pdf->FancyTable($rs); and check if you get the PDF.

Scram answered 4/1, 2013 at 5:17 Comment(5)
FancyTable only have the function to create the pdf file,when i will remove that how can it's work....Eckhart
I've done the download here of the FPDF 1.7 and tried your code. The only problem I had was with this line. Take a look at my example pastebin.com/JmDQwMLkScram
i don't what default value for pdf , i need to create a pdf from database..... $result is a result set.........Eckhart
Here is a example where $rs could be from any source (database, xml, file and so on) pastebin.com/9k1FjgyZScram
I look the file fpdf the issue in font part $this->CoreFonts was null, if i have remove the $pdf->SetFont('Arial','B',14); the Warning: Invalid argument supplied for foreach() in /var/www/html/irmt/library/class/fpdf/fpdf.php on line 1535Eckhart
D
0

Changing the PHP version to 7.4 worked for me

Dependency answered 16/3, 2023 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.