How to Generate Invoice PDF in Laravel?

In this tutorial, I will show you How to Generate Invoice PDF in Laravel. We will use laravel generate invoice pdf. you can understand a concept of how to generate invoice pdf in laravel using dompdf. This tutorial will give you a simple example of lar…


This content originally appeared on DEV Community and was authored by Msh Sayket

In this tutorial, I will show you How to Generate Invoice PDF in Laravel. We will use laravel generate invoice pdf. you can understand a concept of how to generate invoice pdf in laravel using dompdf. This tutorial will give you a simple example of laravel dompdf invoice pdf design. Alright, let’s dive into the steps. You Can Learn Laravel Blade Check If Variable Exists or Not Example

In this guide, I’ll walk you through the process of creating a PDF invoice template design within a Laravel application. We’ll utilize the dompdf composer package to generate the PDF file. The next steps involve crafting straightforward HTML and CSS code to establish a clean and standardized layout for the invoice PDF. Let’s proceed by following the outlined steps:

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

Step 1: Install Laravel 11

This step is not required; however, if you have not created the laravel app, then you may go ahead and execute the below command:

composer create-project laravel/laravel example-app

Step 3: Create Controller

In this step, we will create InvoiceController with index() where we write code to generate pdf. so let’s create a controller using the bellow command.

php artisan make:controller InvoiceController

Now, update the code on the controller file.

app/Http/Controllers/InvoiceController.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade\Pdf;



class InvoiceController extends Controller
{

    /**
     * Write code on Method
     *
     * @return response()
     */

    public function index(Request $request)

    {

        $data = [
            [

                'quantity' => 2,
                'description' => 'Gold',
                'price' => '$500.00'

            ],

            [

                'quantity' => 3,
                'description' => 'Silver',
                'price' => '$300.00'

            ],

            [

                'quantity' => 5,
                'description' => 'Platinum',
                'price' => '$200.00'

            ]

        ];



        $pdf = Pdf::loadView('invoice', ['data' => $data]);
        return $pdf->download();

    }

}

Step 4: Add Route

Furthermore, open the routes/web.php file and update the code on it.

routes/web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\InvoiceController;



/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('invoice-pdf', [InvoiceController::class, 'index']);

Read More


This content originally appeared on DEV Community and was authored by Msh Sayket


Print Share Comment Cite Upload Translate Updates
APA

Msh Sayket | Sciencx (2025-01-05T13:39:22+00:00) How to Generate Invoice PDF in Laravel?. Retrieved from https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/

MLA
" » How to Generate Invoice PDF in Laravel?." Msh Sayket | Sciencx - Sunday January 5, 2025, https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/
HARVARD
Msh Sayket | Sciencx Sunday January 5, 2025 » How to Generate Invoice PDF in Laravel?., viewed ,<https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/>
VANCOUVER
Msh Sayket | Sciencx - » How to Generate Invoice PDF in Laravel?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/
CHICAGO
" » How to Generate Invoice PDF in Laravel?." Msh Sayket | Sciencx - Accessed . https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/
IEEE
" » How to Generate Invoice PDF in Laravel?." Msh Sayket | Sciencx [Online]. Available: https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/. [Accessed: ]
rf:citation
» How to Generate Invoice PDF in Laravel? | Msh Sayket | Sciencx | https://www.scien.cx/2025/01/05/how-to-generate-invoice-pdf-in-laravel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.