Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FPDF - Class 'App\Http\Controllers\FPDF' not found

For my project I have to generate a PDF file. Stackoverflow told me to use FPDF. So, I followed the tutorial but it doesn't seem to work.

public function makePdf(Request $request){
    require('fpdf181/fpdf.php');
    $pdf = new FPDF('p', 'mm', 'A4');
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();   
  }

This is completely following the tutorial but it doesn't work.

I tried this as well:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
require('fpdf181/fpdf.php');

But than again, I get the same error.

like image 729
Marty Avatar asked Jul 01 '26 16:07

Marty


1 Answers

change this:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
require('fpdf181/fpdf.php');

to this:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use FPDF;

because of PSR-4 autoloading namespaces you dont have to include it explicitly.

like image 96
Romantic Dev Avatar answered Jul 03 '26 07:07

Romantic Dev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!