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

mohan
  • 453
  • 1
  • 5
  • 17

4 Answers4

23

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();
       }
    }
  • 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); }` – gthuo Aug 25 '15 at 11:37
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();
    }
}
Joe Black
  • 41
  • 1
1

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

medina
  • 8,051
  • 4
  • 25
  • 24
  • FancyTable only have the function to create the pdf file,when i will remove that how can it's work.... – mohan Jan 04 '13 at 05:20
  • 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 http://pastebin.com/JmDQwMLk – medina Jan 04 '13 at 05:38
  • i don't what default value for pdf , i need to create a pdf from database..... $result is a result set......... – mohan Jan 04 '13 at 05:43
  • Here is a example where $rs could be from any source (database, xml, file and so on) http://pastebin.com/9k1FjgyZ – medina Jan 04 '13 at 06:04
  • 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 1535` – mohan Jan 04 '13 at 06:19
0

Changing the PHP version to 7.4 worked for me

TartanLlama
  • 63,752
  • 13
  • 157
  • 193