Html 2 PDF cakephp

1.Download html2pdf
2.Include the files in controller method as below

$this->autoRender = false;
$this->layout=false;
$id = $this->params['pass'][0];
App::import("Model","Order");
$this->Order=new Order();
$order = $this->Order->find('first', array('conditions'=>array('Order.id'=>$id)));
$view = new View($this, false);
$view->set("order",$order);
$view->viewPath = 'orders';
$view_output = $view->render('admin_order_pdf');

App::import('Vendor','xtcpdf');
$tcpdf = new XTCPDF();
$textfont = 'freesans'; // looks better, finer, and more condensed than 'dejavusans'

$tcpdf->SetAuthor("Worldwide Stone Order Details");
$tcpdf->SetAutoPageBreak( false );
$tcpdf->setHeaderFont(array($textfont,'',10));
$tcpdf->xheadercolor = array(150,250,170);
$tcpdf->xheadertext = '';
$tcpdf->xfootertext = 'Copyright © %d Worldwide Stone Order Details. All rights reserved.';
$html_for_pdf=$view_output;
$tcpdf->AddPage();
//$tcpdf->Cell(0,14, $html_for_pdf, 0,1,'L');


$html_for_pdf=$view_output;
$tcpdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_for_pdf, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
ob_start();
$tcpdf->Output('test.pdf', 'D');
ob_end_flush();
/****************************************************************************/
if (!$id)
{
$this->Session->setFlash('Sorry, there was no property ID submitted.');
$this->redirect(array('action'=>'admin_order_list'), null, true);
}
Configure::write('debug',0); // Otherwise we cannot use this method while developing

$id = intval($id);

// $property = $this->__admin_order_view($id); // here the data is pulled from the database and set for the view
$property = $this->Order->find('first',array('conditions'=>array('Order.id'=>$id)));
// pr($property);

if (empty($property))
{
$this->Session->setFlash('Sorry, there is no property with the submitted ID.');
$this->redirect(array('action'=>'admin_order_list'), null, true);
}


$this->layout = 'pdf'; //this will use the pdf.ctp layout
$this->render();
}

?>

3.The view file to be converted to pdf is

<div><h4><b>Order Details Of </b></h4></div>
<h2>Order Information</h2>
&lt;img width=&quot;100&quot; height=&quot;100&quot; src=&quot;" /&gt;
<p>Order Name :<span><br />
Template Name : <br />
Material  Name : <br />
Material  Id : 
</p>
<h2>Template Information</h2>
<p>Template Title : <br />
Template Price : <br />
Template Price : <br />
Template Created : <br />
Die Id  : <br />
Die Styles : <br />
Die Styles Codes : <br />
Die Styles Complexity : <br />
Die Styles Instances : <br />
Die Styles Special Die Aplicables :<br />
Original width(Single/Double) : <br />
Width in Inches :<br />
Height in Inches  :<br />
Estimated Area in inches  :<br />
Estimated Area in cms :  :<br />
Thickness 4ins :<br />
Thickness 6ins :<br />
Thickness 8ins :
</p>
 
<h2>Material Information</h2>
 
<p>Material Name :<span><br />
Material Price :<span><br />
Material Country Of Origin :<br />
Material Stone Type : <br />
Material Color Tone :<br />
Material Instance : <br />
Material Color Code :<br />
</p>
Advertisements

One thought on “Html 2 PDF cakephp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s