Now first you need to download fpdf.Go to the website below and download the latest version of fpdf.
http://www.fpdf.org/
Create a folder called fpdf in the following directory and unzip the downloaded file in to it..
C:\xampp\htdocs\learncake\app\Vendor
Now it is need to create our MVC now.
First of all...
Open the below file
C:\xampp\htdocs\learncake\app\Config
and paste the below codes in it.
Router::parseExtensions('pdf');
Now I will create the layout.Copy this below codes and save them as pdf.ctp in below directory.
/app/View/Layouts/pdf.ctp
<?php
header('Content-Disposition: attachment; filename="downloaded.pdf"');
echo $content_for_layout;
?>
Now what you need is to create a controller....
Create a new file in the following directory and save it as MysController.php and save below codes in it.
C:\xampp\htdocs\learncake\app\Controller
<?php
class MysController extends AppController{
public function viewpdf() {
App::import('Vendor', 'Fpdf', array('file' => 'fpdf/fpdf.php'));
$this->layout = 'pdf'; //this will use the pdf.ctp layout
$this->set('fpdf', new FPDF('P','mm','A4'));
$this->set('data', 'Hello, PDF world');
$this->render('pdf');
}
}
?>
Now create a folder called Mys in C:\xampp\htdocs\learncake\app\View directory and create a file called pdf.ctp in it.Save the below codes in it.
<?php
$fpdf->AddPage();
$fpdf->SetFont('Arial','B',16);
$fpdf->Cell(40,10,$data);
$fpdf->Output();
?>
Now it is all over go to the browser and type below. http://localhost/learncake/Mys/viewpdf and you will see a pdf file will download.