【发布时间】:2015-08-10 07:36:46
【问题描述】:
我正在尝试在 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();
?>
但最终会出现错误,因为“此 pdf 文档可能无法正确显示。如果我尝试下载并查看,则会显示 “不支持文件类型 HTML 文档 (text/html)”。我添加了 “标头('内容类型:应用程序/pdf');”在没有帮助的情况下查看文件。
谁能帮忙?
【问题讨论】:
-
您没有完全自动加载库。您需要 FPDF 或 MPDF 也可以吗?
-
我需要 FPDF 才能使用。我是 yii 的新手。你能帮忙处理一下吗?
-
你能把你下载的FPDF包的链接发给你吗?