Laravel - FPDF error: Undefined font

1

What I'm doing

I'm rewriting a small bar code generation system using Laravel.

What went wrong

I'm instantiating classes normally, but when I use the $pdf->SetFont('Arial','B',$fontSize); method I get the message FPDF error: Undefined font: helvetica B . As you can see in the image below, the "font" folder is already included inside the library folder. I went into the library and looked for the SetFont method, and just changed the folder path, since the lib e and font file is inside my directory.

My Code

I will leave only small parts of the code

<?php namespace App\Http\Controllers;

//Declaração de uso de elementos para layout, bibliotecas e depois model com bd
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() {

    //parte inicial do código

    //Cria um novo PDF
    $pdf = new eFPDF('P', 'pt');

    //Modifica informações de visualização do PDF
    $pdf->SetFont('Arial','B',$fontSize);

Within the class FPDF.php it has the method below that is called to import the fonts.

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

2 answers

0

First of all, the getPath method was being called but define was not getting the full path of the folder. The dirname of it was not working, so I changed it to app_path().'/Libraries/FPDF/font/' , and at the end of the generatePdf method soon after $pdf->Output I put exit; otherwise the browser would show the characters below:

% PDF-1.3 3 0 obj < > endobj 40 obj < > stream x e N 0 } R < ? W $ @ g ( g ^ r ~ w &) Z ^ cx ; Ώ g G W | E > i̔4c { : r + L & Ʉ ޽ s "Hh & h F2c 2 n ڢ , " L < i e i + I φi i4 ;, f : ۝ $ r ^ - WN ^ [ 7 F U F 1 b f, 9y > | k ^ ~ r [L m l? / U n KxY G7 x ( ak 6r V T = sc 6 { endstream endobj 5 0 obj < > endobj 6 0 obj < > stream x e N 0 } < ? W $ @ g ( g ^ o {i ~ w I stream k W % ư ˺ ݉ qW5 % p ڋ | 6 Ә) i u 4 WN1 L6 { D6 L L d 2 m L k JIiy & Of [ q έa d% q @ 6 A c : z ؄ t v vh @ s @ s R ) b Gy [ (O30 Lts s 7Z Lyb̓H 3 bb gV 4 ' h B P P э4 Q H ڕ R y R qb w ޸ kL y - ; L t > { -F [& gt , K cW + ˰-S ׶ M- - ǰ ~ ^ ߮ (V ~ endstream endobj 7 0 obj

26.03.2015 / 13:12
0

What would this eFPDF be?

An example would be like this

public function gerarPdf() {       
      $fpdf = new Fpdf();
             $fpdf->AddPage();
             $fpdf->SetFont('Arial','B',16);
             $fpdf->Output();
             exit;
}
    
18.03.2015 / 19:28