How to Page Break in PDF using DomPDF Laravel?
In this example, you will learn laravel dompdf page break. I explained simply about laravel-dompdf page-break-after. Here you will learn dompdf page-break laravel example. This example will help you how to page break in dompdf laravel.
If you're looking to add page breaks in dompdf, I can guide you on how to create page breaks in a PDF file using CSS. We'll utilize the CSS property page-break-after: always to initiate page breaks. Now, let's explore a straightforward example code for this purpose.
Now, let's see an example step by step, you can use this example with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 versions:
Step 1: Install Laravel
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 2: Install DomPDF Package
next, we will install the DomPDF package using the following composer command, let's run the below command:
composer require barryvdh/laravel-dompdf
Step 3: Create Controller
In this step, we will create PDFController with generatePDF() where we write the code of generate pdf. so let's create controller using bellow command.
php artisan make:controller PDFController
Now, update the code on the controller file.
class PDFController extends Controller
* Display a listing of the resource.
* @return \Illuminate\Http\Response
public function generatePDF()
$data = [
'title' => 'Welcome to ItSolutionStuff.com',
$pdf = PDF::loadView('myPDF', $data);
Step 4: Add Route
Furthermore, open routes/web.php file and update code on it.
| 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('generate-pdf', [PDFController::class, 'generatePDF']);
Step 5: Create View File
In Last step, let's create myPDF.blade.php(resources/views/myPDF.blade.php) for layout of pdf file and put following code:
<title>Laravel 10 Generate PDF Example - ItSolutionStuff.com</title>
<p>I am writing to formally resign from my position as [Your Position] at [IT Company Name], with my last working day being [Last Working Day], in accordance with the notice period stipulated in my employment contract.</p>
<p>After careful consideration, I have decided to take a new direction in my career. This decision wasn't easy, as I have cherished my time here and the projects we've accomplished together. I am immensely proud of our collective achievements.</p>
<p>During my notice period, I am committed to ensuring a seamless transition. I am more than willing to assist in the transfer of my responsibilities, provide training to my successor, and complete any pending projects. Please let me know how I can best contribute to this process.</p>
Run Laravel App:
All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:
php artisan serve
Now, Go to your web browser, type the given URL and view the app output:
you will download the file below:
Now we are ready to run this example and check it...
I hope it can help you...
We are Recommending you
- How to Add Header and Footer in Dompdf Laravel?
- Laravel Dompdf Add Custom Font Family Example
- Laravel Dompdf Set Custom Paper Size Example
- How to Add Digital Signature in PDF using Laravel?
- How to Read Content from PDF File in Laravel?
- Laravel 10 Generate PDF and Send Email Example
- How to Merge Multiple PDF Files in Laravel 10?
- Laravel 10 Generate PDF File using DomPDF Example
- Laravel TCPDF: Generate HTML to PDF File Example
- Laravel Mail Send with PDF Attachment Example
- Laravel Convert PDF to Image Example
- How to Generate PDF and Send Email in Laravel?
- Laravel Datatables Export to PDF File Example
- Laravel Create PDF File with Image Example