Achieve the World’s Most Prestigious Certifications and Unlock Top-Paying Careers! Get Certified in the Industry’s Leading Programs Today.
🚀 DevOps Certified Professional 🚀 SRE Certified Professional 🚀 DevSecOps Certified Professional 🚀 MLOps Certified Professional
📅 Starting: 1st of Every Month 🤝 +91 8409492687 | 🤝 +1 (469) 756-6329 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

In Laravel, Generate PDF from Using DOM PDF

First we have to create project in htdocs Ex: pdfcreator

Then go inside the project

Then we have to install composer

$ composer require barryvdh/laravel-dompdf

Now serve the page to browser

php artisan serve

Then page is opening successfully

Then go to your texteditor and go to C:\xampp\htdocs\pdfcreator\config\app.php

And write this in  

‘providers’ =>

Barryvdh\DomPDF\ServiceProvider::class,

And write this in  

‘aliases’ =>

‘PDF’ => Barryvdh\DomPDF\Facade::class,

Now we have to make Controller

php artisan make:controller PDFController

And write this code

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PDF;
class PDFController extends Controller
{
public function show(){
return view('page');
}
public function generatePDF(){
$data =[
'title' => 'Welcome TO PDF Page',
'date' => date('m/d/y')
];
$pdf = PDF::loadView('index', $data);
return $pdf->download('First.pdf');
}
}

Now we make route

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PDFController;
/*
|--------------------------------------------------------------------------
| 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('/show',[PDFController::class, 'show']);
Route::get('/generate-pdf',[PDFController::class, 'generatePDF']);

Make blade page with name index.blade.php in resources/view

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>{{ $title }}</h1>
<p>Date ;- {{ $date }}</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Autem iure fugiat repudiandae amet quae inventore sed mollitia ipsum voluptas omnis voluptates, saepe et ab incidunt quos quis qui aliquid iste.</p>
<form action="" method="post">
<input type="text">
<img src="" alt="">
<button></button>
</form>
</body>
</html>

Make another blade page with name page.blade.php in resources/view

<a href="/generate-pdf">Click To Download PDF</a>

Then run 127.0.0.1:8000/show/

After Clicking on button you got PDF file

With your content

Related Posts

How to Resolve Laravel Dusk Installation Issues: Missing ext-zip and PHP Compatibility

Laravel Dusk is a powerful browser automation and testing tool that allows you to test the front-end of your Laravel application in real-time. However, if you’re encountering…

Testing the Capabilities of Your Laravel Application: Tools and Software to Use

As a developer working with Laravel, ensuring that your application performs efficiently, scales well, and provides a seamless experience for users is crucial. Whether you’re building a…

Implementing Retry Logic with Exponential Backoff

In modern web applications, API calls and network requests play a crucial role in retrieving data or interacting with external services. However, one common challenge developers face…

How to Resolve the “429 Too Many Requests” Error

The 429 Too Many Requests error occurs when a server is overwhelmed by too many requests in a short period. It’s a common issue when interacting with…

Best Tech websites in the world in 2025

AIOps School AIOps School is a learning platform focused on AI-powered IT operations (AIOps) and Machine Learning Ops (MLOps). Branded as the “Gateway to AI-Powered IT &…

Why DevOps Consulting is Essential for Modern Enterprises

In today’s fast-paced digital landscape, businesses must adapt quickly to stay competitive. Traditional software development and IT operations models often lead to bottlenecks, inefficiencies, and deployment delays….

0 0 votes
Article Rating
Subscribe
Notify of
guest


0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x