Laravel - FPDF error: Undefined font

Asked

Viewed 599 times

1

What am I doing

I’m rewriting a small barcode generation system using Laravel.

What went wrong

I’m instantiating the classes normally, but when I use the method $pdf->SetFont('Arial','B',$fontSize); I get the message FPDF error: Undefined font: Helvetica B. As you can see in the screenshot below, the "font" folder is already included inside the library folder. I entered inside the library and searched for the method Setfont, and only changed the folder path, since the lib and font file is inside my directory.

inserir a descrição da imagem aqui

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 FPDF.php class 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 : '';
}
  • I believe this is the best solution;Solution in English

  • @Adrianocarvalho Yes, he has a class that extends PDF :S, it is the way it is in this text.

  • You even set the sources directory of the FPDF define('FPDF_FONTPATH','font/');? The class has no method constructor?

2 answers

0


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

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x and 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�:���۝� ���$<4�9�9��qE���Q�M�i&21���n�^X�~��N+{�)O�yi�tVL�Y��*�f����]Hjj�t#M�B���m�6��>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��k������W�%ư��˺݉�����qW۵��%�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[>��K�����cW+˰-S׶���M-�-�ǰ~^߮? (V' endstream endobj 7 0 obj <> endobj 8 0 obj <> stream x and N1 < Kh w[$@ g"5 υ3 I | z' S Jߧ -<�/1��^����~���r���$�����Q�Q��8�l��;�?��� d��s\�L�e&Wh�D6��\�6�I3�@&�I$3Ι1����Y�Y�L��8ςK��� mq�R1ۊn+��n� �6t۠m�ۆn;���6�m�l;��趻�vxvȠ��ӰC�M0h��"F�����Q�f`"���+�b%�j�7Z��L�ʘ�"�����#+�Y%�̞�!�� L:ӛ��n����}z����y��m�켲�귥�ƘG1�C<э��L�����1����)���ۧSƙ3�b���N��ߟ����-/V�L]e�%> endobj 10 0 obj <> stream x�e��N1��<�Kh���n����! H�Լ>�H�-M�U�ˌ�;��Oq��O�kxzUP_b�9���7q��v���뵵�%�p v/��"E���i̔4c{��:� r�+���L�:� �{�DHh&h&#�5�d�E����Z�R�9+4k�Ɋ�U�Y1���4�V7���mp�ඹ�5���Nf����n͹����n�������i���&��C��"&z�����4����Dw^ �pWGy��=͔'�<��O:+&V��|f�I3{b���.���� y��4����w�v%]ݟ��nܖF�ΛߖF�Ɖ'ּs��Ÿ-�w��V�sFQ>�b45�|йO����}4������������e�-S׶���Gj���������~� endstream endobj 1 0 obj <> endobj 11 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 11 0 R >> /XObject << >> >> endobj 12 0 obj << /Producer (FPDF 1.6) /Creationdate (D:20150326120906) >> endobj 13 0 obj << /Type /Catalog /Pages 1 0 R /Openaction [3 0 R /Fith null] /Pagelayout /Onecolumn >> endobj xref 0 14 0000000000 65535 f 0000002164 00000 n 0000002371 00000 n 00000000000009 00000 n 0000000087 00000 n 0000000542 00000 n 0000000620 00000 n 0000001077 00000 n 0000001155 00000 n 0000001619 00000 n 0000001698 00000 n 0000002269 00000 n 0000002476 00000 n 0000002552 00000 n trailer << /Size 14 /Root 13 0 R /Info 12 0 R >> startxref 2656 %EOF

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;
}
  • In the link you sent me the guy created "class pdf extends FPDF", and called the parent class builder. Ess my ePDF is the same thing, it would be the "pdf" using this example.

  • https://github.com/xroot/laravel-fpdf

  • This is a problem with the repository when running Composer update.

  • Sorry to get out of the point! What was the bug with Poser ?

  • http://s15.postimg.org/uitl181v/composer.png - the bug http://postimg.org/image/m2g81g3rv/ - my Composer

  • The error in question is lib in "dev-master"! Tries to put your lib all in dev-master or all with its latest version... The problem with the error is that it gives incompatibility error with the lib "Illuminate/support": "5.1. *@dev" of Laravel 5 with Illuminate having depedencies 4.0.1

  • I did that and it was a mistake - http://s13.postimg.org/nfoa7srjr/composer.png, screenshot of my Poser.json. Still missing something ?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.