Tampilkan postingan dengan label Laravel. Tampilkan semua postingan
Tampilkan postingan dengan label Laravel. Tampilkan semua postingan

Kamis, 15 Juli 2021

How to use FPDF in Laravel

1. First install the FPDF package

$ composer require codedge/laravel-fpdf

2. Creating a PDF Function on your Controller or Seperated Controller like example below

<?php namespace App\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Codedge\Fpdf\Fpdf\Fpdf; class PDFController extends Controller { private $fpdf; public function __construct() { } public function createPDF() { $this->fpdf = new Fpdf; $this->fpdf->AddPage("L", ['100', '100']); $this->fpdf->Text(10, 10, "Hello FPDF"); $this->fpdf->Output(); exit; } }

Notes :

- fpdf output option :

$this->fpdf->Output(public_path('/tmp_pdf/').filename.pdf,'D');

I: send the file inline to the browser. The PDF viewer is used if available.
D: send to the browser and force a file download with the name given by name.
F: save to a local file with the name given by name (may include a path).
S: return the document as a string.

- for more documentation about FPDF visit http://www.fpdf.org/