我正在使用mPDF来生成工资单.但是,生成后,工资单中的图标不会显示.它只留下一个空白区域:
图标应显示在突出显示的位置上.
到目前为止,这就是我所做的:
我正在使用Yii2 PHP框架,这是我的动作控制器:
public function actionPdf($id)
{
$model = $this->findModel($id);
$earnings = EarningDetails::find()->where(['payslip_id' => $model->_id, 'status' => 1])->all();
$deductions = DeductionDetails::find()->where(['payslip_id' => $model->_id, 'status' => 1])->all();
$html = $this->render('view', [
'model' => $model,
'earnings' => $earnings,
'deductions' => $deductions,
]);
$mpdf = new mPDF('c','A5-L','0','',0,4,1,1,0,0);
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'windows-1252';
$mpdf->SetTopMargin(0);
$user_password = User::find()->where(['_id' => $model->user_id ])->one();
$password = $user_password->fname.$user_password->lname;
$mpdf->SetProtection(array(), $password, $password);
$mpdf->WriteHTML($html);
$mpdf->Output('Payslip.pdf', 'D');
exit;
}
我错过了什么吗?请告诉我.
解决方法:
除了编码问题,这可能是一些事情.首先,您需要将FontAwesome与MPDF安装集成.其次,您需要考虑如何在HTML中设置字形.
在mPDF中安装FontAwesome
从https://github.com/FortAwesome/Font-Awesome下载或克隆FontAwesome并将fonts / fontawesome-webfont.ttf复制到MPDF ttfonts /目录中.
在MDPF config_fonts.php文件中,将以下行添加到$this-> fontdata:
/* FontAwesome */
"fontawesome" => array(
'R' => "fontawesome-webfont.ttf"
),
在HTML中添加字形
您需要记住,CSS:在通常用于将FontAwesome字形添加到HTML的伪选择器之前在mPDF中不起作用.
坏:
…因为这个FontAwesome CSS规则在mPDF中不起作用:
.fa-smile-o:before {
content: "\f118";
}
好:
您可以通过在FontAwesome图标列表上单击来获取每个字形的unicode代码点,但Cheatsheet更方便.
标签:mpdf,php,pdf,icons
来源: https://codeday.me/bug/20191003/1849861.html