# Laravel Packages
# DataTable
datatables.yajrabox.com (opens new window)
# Install Laravel Datatables Package
# Install using composer.
composer require yajra/laravel-datatables-oracle
# Add Datatables Service Provider and Facade on config/app.php.
Yajra\Datatables\DatatablesServiceProvider::class,
'Datatables' => Yajra\Datatables\Facades\Datatables::class,
# Lastly, publish the configuration file.
php artisan vendor:publish
# Install DataTables Assets
# Css
//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css
# jQuery
//code.jquery.com/jquery-1.10.2.min.js
# DataTables
//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js
# Spatie Permission
# Install Laravel Spatie Permission Package
# Install using composer.
composer require spatie/laravel-permission
# You may manually add the service provider in your config/app.php file:
'providers' => [
// ...
Spatie\Permission\PermissionServiceProvider::class,
];
2
3
4
# You should publish the migration and the config/permission.php config file with:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
# Clear your config cache.
This package requires access to the permission config. Generally it's bad practice to do config-caching in a development environment. If you've been caching configurations locally, clear your config cache with either of these commands:
php artisan optimize:clear
# or
php artisan config:clear
2
3
# Run the migrations
After the config and migration have been published and configured, you can create the tables for this package by running:
php artisan migrate
# MPDF
# Install Laravel MPDF Package
Easily generate PDF documents from HTML right inside of Laravel using this mpdf wrapper.
# Installation.
Require this package in your composer.json
"require": {
carlos-meneses/laravel-mpdf: "2.1.8"
}
2
3
or install it by running:
composer require carlos-meneses/laravel-mpdf
To start using Laravel, add the Service Provider and the Facade to your config/app.php:
'providers' => [
// ...
Meneses\LaravelMpdf\LaravelMpdfServiceProvider::class
]
2
3
4
'aliases' => [
// ...
'PDF' => Meneses\LaravelMpdf\Facades\LaravelMpdf::class
]
2
3
4
# Basic Usage
To use Laravel Mpdf add something like this to one of your controllers. You can pass data to a view in /resources/views.
//....
use PDF;
class ReportController extends Controller {
public function generate_pdf()
{
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
return $pdf->stream('document.pdf');
}
}
2
3
4
5
6
7
8
9
10
11
12
# Config
You can use a custom file to overwrite the default configuration.
Just execute php artisan vendor:publish --tag=mpdf-config or create config/pdf.php and add this:
return [
'mode' => '',
'format' => 'A4',
'default_font_size' => '12',
'default_font' => 'sans-serif',
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 10,
'margin_bottom' => 10,
'margin_header' => 0,
'margin_footer' => 0,
'orientation' => 'P',
'title' => 'Laravel mPDF',
'author' => '',
'watermark' => '',
'show_watermark' => false,
'show_watermark_image' => false,
'watermark_font' => 'sans-serif',
'display_mode' => 'fullpage',
'watermark_text_alpha' => 0.1,
'watermark_image_path' => '',
'watermark_image_alpha' => 0.2,
'watermark_image_size' => 'D',
'watermark_image_position' => 'P',
'custom_font_dir' => '',
'custom_font_data' => [],
'auto_language_detection' => false,
'temp_dir' => rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR),
'pdfa' => false,
'pdfaauto' => false,
'use_active_forms' => false,
];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
To override this configuration on a per-file basis use the fourth parameter of the initializing call like this:
PDF::loadView('pdf', $data, [], [
'title' => 'Another Title',
'margin_top' => 0
])->save($pdfFilePath);
2
3
4
# Headers and Footers
If you want to have headers and footers that appear on every page, add them to your <body> tag like this:
<htmlpageheader name="page-header">
Your Header Content
</htmlpageheader>
<htmlpagefooter name="page-footer">
Your Footer Content
</htmlpagefooter>
2
3
4
5
6
7
Now you just need to define them with the name attribute in your CSS:
@page {
header: page-header;
footer: page-footer;
}
2
3
4
Inside of headers and footers {PAGENO} can be used to display the page number.
# Custom Fonts
You can use your own fonts in the generated PDFs.
The TTF files have to be located in one folder,
e.g. resources/fonts/. Add this to your configuration file (/config/pdf.php):
return [
'custom_font_dir' => base_path('resources/fonts/'), // don't forget the trailing slash!
'custom_font_data' => [
'examplefont' => [
'R' => 'ExampleFont-Regular.ttf', // regular font
'B' => 'ExampleFont-Bold.ttf', // optional: bold font
'I' => 'ExampleFont-Italic.ttf', // optional: italic font
'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
]
// ...add as many as you want.
]
];
2
3
4
5
6
7
8
9
10
11
12
Now you can use the font in CSS:
body {
font-family: 'examplefont', sans-serif;
}
2
3
# Get instance your Mpdf
You can access all mpdf methods through the mpdf instance with getMpdf().
use PDF;
$pdf = PDF::loadView('pdf.document', $data);
$pdf->getMpdf()->AddPage(...);
2
3
4