【发布时间】:2018-01-09 18:26:27
【问题描述】:
我正在使用 FPDI 从 Laravel 5 项目中的 template.pdf 文件生成 PDF,但由于 FDPI 本身不支持编码,所以我遇到了 UTF-8 名称的问题。
我做了很多搜索,tFPDF 和 TCPDF 似乎是这个问题最常用的解决方案,尽管我似乎无法成功地将它们中的任何一个集成到我的 laravel 应用程序中。
我已经参考了这些链接,但没有运气:
带有 tFPDF 的 FPDI:https://www.setasign.com/products/fpdi/demos/legacy-v1/
带有 TCPDF 的 FPDI:https://www.setasign.com/products/fpdi/demos/tcpdf-demo/
这是我在 laravel 控制器中使用的 PHP 函数。
public static function generateCertificate($firstname, $fullname, $course_name, $level, $date, $output, $email = null, $certificate_link = null)
{
$fullname = stripslashes($fullname);
$fullname = 'Witaj świecie'; //Added to debug issue
//Start PDF Generation
$pdf = new \setasign\Fpdi\Fpdi();
//Set Template
$path = app()->publicpath().'/assets/templates/examination_level100_certificate.pdf';
$pageCount = $pdf->setSourceFile($path);
$template = $pdf->importPage(1);
$size = $pdf->getTemplateSize($template);
$pdf->addPage();
$pdf->useTemplate($template, null, null, null, null, true);
//Add the fonts
$pdf->AddFont('Myriad-pro', '', 'myriad-pro-regular.php');
$pdf->AddFont('Myriad-pro-semibold', '', 'myriad-pro-semibold.php');
//Set Title
$pdf->SetTitle($fullname.' - '.str_replace(' - ', ' ', $course_name).' - Certicifate');
//Add User Name
$pdf->SetFont('Arial', '', 40);
$pdf->SetTextColor(67, 156, 209);
$pdf->SetY(164);
$pdf->Cell(0, 20, $fullname, 0, 1, 'C');
$pdf->Output('I', str_slug($fullname.'-'.$course_name).'.pdf', true);
}
【问题讨论】: