2013-01-04 35 views
7

我是fpdf庫的新手,我需要在smarty中創建一個來自數據庫的pdf。我已經檢查了數據從數據的基礎是好的,當傳遞字體名稱下面的錯誤是顯示未定義的字體:在Fpdf

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 

我的代碼是

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

請幫助我,我怎麼能解決這個問題。 謝謝

回答

19

我覺得你在創建PDF __construct是問題,試試這個在

require_once("fpdf.php"); 
    class pdf extends FPDF 
    { 
     function __construct() 
     { 
      parent::FPDF(); 
     } 
    } 
+0

好的。那個人真的爲我工作。爲了補充這一點,可能更希望將幾個參數傳遞給構造函數,然後傳遞給FPDF類,例如方向等。這就是我爲頁面橫向定位必須做的事情: 'function __construct($定位,$單位,$大小) \t {\t \t \t parent :: FPDF($ orientation,$ units,$ size); \t}' – gthuo

1

嘗試刪除行$ pdf-> FancyTable($ rs);並檢查你是否得到PDF。

+0

FancyTable只需要創建PDF文件,當我將刪除功能如何能的工作.... – mohan

+0

我在這裏所做的FPDF 1.7的下載並嘗試了你的代碼。我遇到的唯一問題就是這條線。看看我的例子http://pastebin.com/JmDQwMLk – medina

+0

我不是什麼默認值的PDF,我需要從數據庫創建一個PDF ..... $結果是一個結果集..... .... – mohan

1

那是因爲你調用FPDF庫的構造函數,改變FPDF庫函數(參數)__構建(參數),然後從您的文件中傳播它。 例如: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(); 
    } 
}