Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use in a controller? #18

Closed
BenjaminHoegh opened this issue Mar 16, 2018 · 2 comments
Closed

How to use in a controller? #18

BenjaminHoegh opened this issue Mar 16, 2018 · 2 comments

Comments

@BenjaminHoegh
Copy link

How to use in a controller?

Laravel 5.6

@barisbora
Copy link

For example POST Method in your controller, Laravel auto resolver create instance for you. Also u can statically call class

public function store(Request $request, Codedge\Fpdf\Fpdf\Fpdf $fpdf) {

    $fpdf->AddPage();
    $fpdf->SetFont('Courier', 'B', 18);
    $fpdf->Cell(50, 25, 'Hello World!');
    $fpdf->Output();

});

@codedge codedge closed this as completed Jul 13, 2018
@sbarbosa115
Copy link

sbarbosa115 commented Nov 7, 2018

This code works for my using Laravel 5.6 and codedge/laravel-fpdf 1.2

public function print($id): BinaryFileResponse
{
        $pathFile = storage_path(). '/recipe.pdf';
        Fpdf::AddPage();
        Fpdf::SetFont('Courier', 'B', 18);
        Fpdf::Cell(50, 25, 'Hello World!');
        Fpdf::Output('F', $pathFile);
        $headers = ['Content-Type' => 'application/pdf'];
        return response()->file($pathFile, $headers);
}

Do not forget to import FPDF facade.

use Codedge\Fpdf\Facades\Fpdf;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants