Support the ongoing development of Laravel.io →
posted 7 years ago
Lumen

I created a new project with Lumen 5.4.7 and I added the TCPDF library from elibyy/tcpdf-laravel version 5.4.2 (with Lumen support):

composer require elibyy/tcpdf-laravel "5.4.2"

I enabled the Facades and Service Provider in bootstrap/app.php with

$app->withFacades();
$app->register(Elibyy\TCPDF\ServiceProvider::class);

And I created a basic Controller:

<?php

namespace App\Http\Controllers;
use \PDF;

class PdfController extends Controller
{
    /**
     * Create a test PDF file.
     *
     * @return void
     */
    public function createTestPdf()
    {
      PDF::SetTitle('Hello World');
      PDF::AddPage();
      PDF::Write(0, 'Hello World');
      PDF::Output('hello_world.pdf');

      echo "Fatto!";
    }
}

with a basic route:

$app->get('pdf', 'PdfController@createTestPdf');
But when I try to access to /pdf I get the following error:

Fatal error: Class 'PDF' not found in /Users/m/Documents/Projects/lumen-pdf/app/Http/Controllers/PdfController.php on line 15

(1/1) FatalErrorException
Class 'PDF' not found
in PdfController.php (line 15)
at Application->handleShutdown()
in RegistersExceptionHandlers.php (line 54)
at Application->Laravel\Lumen\Concerns\{closure}()

Could you help me please?

Last updated 3 years ago.
0

I solved my problem.

One line was missing into bootstrap/app.php to add a new class_alias for Elibyy\TCPDF\Facades\TCPDF to PDF:

class_alias('Elibyy\TCPDF\Facades\TCPDF', 'PDF');

Thanks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

decibel83 decibel83 Joined 23 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.