1. Go to this page and download the library: Download tjgazel/laravel-fpdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tjgazel / laravel-fpdf example snippets
composer
use App\Http\Controllers\Controller;
use TGazel\LaraFpdf\Facades\LaraFpdf;
class MyController extends Controller
{
public function index()
{
LaraFpdf::AddPage();
LaraFpdf::SetFont('Courier', 'B', 18);
LaraFpdf::Cell(50, 25, 'Hello World!');
LaraFpdf::Output('I', "MyPdf.pdf", true);
exit;
}
}
namespace App\Pdf;
use TJGazel\LaraFpdf\LaraFpdf;
class MyPdf extends LaraFpdf
{
private $data
public function __construct($data)
{
$this->data = $data;
parent::__construct('P', 'mm', 'A4');
$this->SetA4();
$this->SetTitle('My pdf title', true);
$this->SetAuthor('TJGazel', true);
$this->AddPage('L');
$this->Body();
}
public function Header()
{
// fixed all pages
}
public function Body()
{
$this->SetFont('Arial', 'B', '24');
$this->Cell(50, 25, $this->data->title);
$this->SetFont('Arial', '', '14');
$this->Cell(50, 25, $this->data->content);
}
public function Footer()
{
// fixed all pages
}
}
use App\Http\Controllers\Controller;
use App\Pdf\MyPdf;
class MyController extends Controller
{
public function index()
{
$data = MyModel::all();
$myPdf = new MyPdf($data);
$myPdf->Output('I', "MyPdf.pdf", true);
exit;
}
}