在Yii供应商中安装fpdf

时间:2015-08-10 07:36:46

标签: php yii fpdf

我正在尝试使用yii中的fpdf类。所以我导入了yii vendor文件夹中的总fpdf文件夹,然后尝试导入视图文件,如:

Yii::import('application.vendors.*');
require_once('fpdf/fpdf.php');

然后只需粘贴一个类,如下所示

class PDF extends FPDF
{
// Page header
function Header()
{
    // Logo
    $this->Image('logo.png',10,6,30);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(30,10,'Title',1,0,'C');
    // Line break
    $this->Ln(20);
}

// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();
?>

但最终会出现错误,因为&#34;此pdf文档可能无法正确显示。如果我尝试下载并查看,那么它说 &#34;不支持文件类型HTML文档(text / html)&#34;。我补充道 &#34;标题(&#39;内容类型:application / pdf&#39;);&#34;在没有帮助的视图文件上。

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

以下是我的推荐。

首先,按照此说明开始在项目中使用composer。 http://main.org.ua/yii1-composer/

这是未来,值得学习。

然后,使用composer https://packagist.org/packages/itbz/fpdf

安装此软件包

你已经完成了。

自定义自动加载器不再包含手册或麻烦。