我正在尝试在 yii 中使用 fpdf 类。所以我在 yii vendor 文件夹中导入了整个 fpdf 文件夹,然后尝试在 View 文件中导入,例如:
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)”。我加了 “header('Content-Type: application/pdf');”在没有帮助的情况下查看文件。
谁能帮忙?
最佳答案
这是我的建议。
首先,按照此说明开始在您的项目中使用 Composer。 http://main.org.ua/yii1-composer/
很有前途,值得学习。
然后,使用 composer 安装这个包 https://packagist.org/packages/itbz/fpdf
大功告成。
不再有手动包含或自定义自动加载器的问题。
关于php - 在 Yii 供应商中安装 fpdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31914000/