【问题标题】:Laravel - FPDF error: Undefined fontLaravel - FPDF错误:未定义的字体
【发布时间】:2015-03-24 17:15:36
【问题描述】:

我在做什么

我一直在使用 Laravel 重写一个条形码生成系统。

怎么了

我正在正常实例化类,但使用方法 $pdf->SetFont('Arial','B',$fontSize); 我收到错误消息 FPDF 错误:未定义字体:helvetica B。如下所示,粘贴“字体”已包含在库粘贴中。

我的代码

<?php namespace App\Http\Controllers;

//Elements declaration of layout, libraries and model
use View, Input, Validator, FPDF, eFPDF, BarcodeClass, BarcodeEAN, DB, App\Models\Barcode;

class HomeController extends Controller {

public function index() {
    return view('frontend.home');
}

public function gerarPdf() {

    //some code

    //Creates a new PDF
    $pdf = new eFPDF('P', 'pt');

    //Modify PDF font
    $pdf->SetFont('Arial','B',$fontSize);

FPDF.php 内部

function _getfontpath()
{
    if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'font/'))
        define('FPDF_FONTPATH',dirname(__FILE__).'/font/');
    return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
}

【问题讨论】:

    标签: php laravel laravel-5 fpdf


    【解决方案1】:

    首先,getPath 方法是必需的,但是 define 没有收到孔粘贴的文件夹。它的dirname 不起作用,所以我切换到app_path().'/Libraries/FPDF/font/',在方法的最后,我把exit; 放在$pdf-&gt;Output 之后。如果没有,浏览器会显示以下字符:

    %PDF-1.3 3 0 obj endobj 4 0 obj 流 x�e��N�0��} �R

    【讨论】:

      猜你喜欢
      • 2012-04-13
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 2018-08-19
      相关资源
      最近更新 更多