Hi Developers,
Lets see how to create Invoice PDF Generator In Laravel 9, To create invoice pdf generator we are using the barryvdh/laravel-dompdf package by the barryvdh . By using the barryvdh/laravel-dompdf package we can seamlessly create the invoice generator in laravel Application
Explore Laravel 9's robust features in our tutorial on creating a seamless Invoice PDF Generator. Simplify invoicing with step-by-step guidance, ensuring efficient, customized solutions for your business.
Lets install the laravel project using the following artisan command
laravel new invoice_generator
then we install the barryvdh/laravel-dompdf package using the following command,
composer require barryvdh/laravel-dompdf
Lets add the configurations of the installed package in the app.php file
config/app.php
'providers' => [
....
Barryvdh\DomPDF\ServiceProvider::class,
],
'aliases' => [
....
'PDF' => Barryvdh\DomPDF\Facade::class,
]
Lets create the required routes,
routes/web.phpr
<?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('/', function () {
return view('welcome');
});
Route::get('invoice', [InvoiceController::class, 'Invoice']);
Lets create the controller file using the following artisan command ,
php artisan make:controller InvoiceController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PDF;
class InvoiceController extends Controller
{
public function Invoice()
{
$pdf = PDF::loadView('invoice_pdf');
return $pdf->download('itsolutionsguides.pdf');
}
}
Lets create the design for the invoice pdf in the blade file
resources/views/invoice_pdf.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Invoice PDF Generator In Laravel 9 - ITSolutionsGuides</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
</head>
<style type="text/css">
body {
font-family: 'Roboto Condensed', sans-serif;
}
.m-0 {
margin: 0px;
}
.p-0 {
padding: 0px;
}
.pt-5 {
padding-top: 5px;
}
.mt-10 {
margin-top: 10px;
}
.text-center {
text-align: center !important;
}
.w-100 {
width: 100%;
}
.w-50 {
width: 50%;
}
.w-85 {
width: 85%;
}
.w-15 {
width: 15%;
}
.logo img {
width: 200px;
height: 60px;
}
.gray-color {
color: #5D5D5D;
}
.text-bold {
font-weight: bold;
}
.border {
border: 1px solid black;
}
table tr,
th,
td {
border: 1px solid #d2d2d2;
border-collapse: collapse;
padding: 7px 8px;
}
table tr th {
background: #F4F4F4;
font-size: 15px;
}
table tr td {
font-size: 13px;
}
table {
border-collapse: collapse;
}
.box-text p {
line-height: 10px;
}
.float-left {
float: left;
}
.total-part {
font-size: 16px;
line-height: 12px;
}
.total-right p {
padding-right: 20px;
}
</style>
<body>
<div class="head-title">
<h1 class="text-center m-0 p-0">Invoice</h1>
</div>
<div class="add-detail mt-10">
<div class="w-50 float-left mt-10">
<p class="m-0 pt-5 text-bold w-100">Invoice Id - <span class="gray-color">#1</span></p>
<p class="m-0 pt-5 text-bold w-100">Order Id - <span class="gray-color">AB123456A</span></p>
<p class="m-0 pt-5 text-bold w-100">Order Date - <span class="gray-color">26-11-2023</span></p>
</div>
<div class="w-50 float-left logo mt-10">
<img src="https://itsolutionsguides.com/website/images/logo/logo_black.png" alt="Logo">
</div>
<div style="clear: both;"></div>
</div>
<div class="table-section bill-tbl w-100 mt-10">
<div class="row">
<div class="col-6">
<p><span class="fw-bold">From :</span></p>
<p>ITSolutionsGuides</p>
<p>India</p>
<p>Contact: +91 9xxxxxxxxx</p>
</div>
<div class="col-6">
<p><span class="fw-bold">To :</span></p>
<p>Google</p>
<p>United States</p>
<p>Contact: +91 9xxxxxxxxx</p>
</div>
</div>
</div><br><br>
<div class="table-section bill-tbl w-100 mt-10">
<div class="row">
<div class="col-6">
<p><span class="fw-bold">Payment Method :</span>Cash On Delivery</p>
</div>
<div class="col-6">
<p><span class="fw-bold">Shipping Method :</span>Free Shipping - Free Shipping</p>
</div>
</div>
</div>
<div class="table-section bill-tbl w-100 mt-10">
<table class="table w-100 mt-10">
<tr>
<th class="w-50">Dealer</th>
<th class="w-50">Product Name</th>
<th class="w-50">Price</th>
<th class="w-50">Qty</th>
<th class="w-50">Subtotal</th>
<th class="w-50">Tax Amount</th>
<th class="w-50">Grand Total</th>
</tr>
<tr align="center">
<td>Raja</td>
<td>Andoid Smart Phone</td>
<td>₹500.2</td>
<td>3</td>
<td>₹1500</td>
<td>₹50</td>
<td>₹1550.20</td>
</tr>
<tr align="center">
<td>Rajesh</td>
<td>Andoid Smart Phone</td>
<td>₹250</td>
<td>2</td>
<td>₹500</td>
<td>₹50</td>
<td>₹550.00</td>
</tr>
<tr align="center">
<td>Mahesh</td>
<td>Andoid Smart Phone</td>
<td>₹1000</td>
<td>5</td>
<td>₹5000</td>
<td>₹500</td>
<td>₹5500.00</td>
</tr>
<tr>
<td colspan="7">
<div class="total-part">
<div class="total-left w-85 float-left" align="right">
<p>Sub Total</p>
<p>Tax (18%)</p>
<p>Total Payable</p>
</div>
<div class="total-right w-15 float-left text-bold" align="right">
<p>₹7600</p>
<p>₹400</p>
<p>₹8000.00</p>
</div>
<div style="clear: both;"></div>
</div>
</td>
</tr>
</table>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</html>
Now lets run the laravel application by using the following artisan command,
php artisan serve
We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides