Html 2 PDF cakephp

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

$this->autoRender = false;
$id = $this->params[‘pass’][0];
$this->Order=new Order();
$order = $this->Order->find(‘first’, array(‘conditions’=>array(‘’=>$id)));
$view = new View($this, false);
$view->viewPath = ‘orders’;
$view_output = $view->render(‘admin_order_pdf’);

$tcpdf = new XTCPDF();
$textfont = ‘freesans’; // looks better, finer, and more condensed than ‘dejavusans’

$tcpdf->SetAuthor(“Worldwide Stone Order Details”);
$tcpdf->SetAutoPageBreak( false );
$tcpdf->xheadercolor = array(150,250,170);
$tcpdf->xheadertext = ”;
$tcpdf->xfootertext = ‘Copyright © %d Worldwide Stone Order Details. All rights reserved.’;
//$tcpdf->Cell(0,14, $html_for_pdf, 0,1,’L’);

$tcpdf->writeHTMLCell($w=0, $h=0, $x=”, $y=”, $html_for_pdf, $border=0, $ln=1, $fill=0, $reseth=true, $align=”, $autopadding=true);
$tcpdf->Output(‘test.pdf’, ‘D’);
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(‘’=>$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

3.The view file to be converted to pdf is

<div><h4><b>Order Details Of <?php echo $order[‘Order’][‘order’];?></b></h4></div>
<h2>Order Information</h2>
<img width=”100″ height=”100″ src=”<?php echo BASE_URL.”img/fancy_images/”.$order[‘Template’][‘image’];?>” />
<p>Order Name :<span><?php echo $order[‘Order’][‘order’];?><br/>
Template Name : <?php echo $order[‘Template’][‘title’];?><br/>
Material  Name : <?php echo $order[‘Material’][‘name’];?><br/>
Material  Id : <?php echo $order[‘Material’][‘material_id’];?>
<h2>Template Information</h2>
<p>Template Title : <?php if( $order[‘Template’][‘title’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘title’];}?><br/>
Template Price : <?php if( $order[‘Template’][‘price’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘price’];}?><br/>
Template Price : <?php if( $order[‘Template’][‘price’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘price’];}?><br/>
Template Created : <?php if( $order[‘Template’][‘created’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘created’];}?><br/>
Die Id  : <?php if( $order[‘Template’][‘die_id’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘die_id’];}?><br/>
Die Styles : <?php if( $order[‘Template’][‘styles’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘styles’];}?><br/>
Die Styles Codes : <?php if( $order[‘Template’][‘style_codes’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘style_codes’];}?><br/>
Die Styles Complexity : <?php if( $order[‘Template’][‘complexity’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘complexity’];}?><br/>
Die Styles Instances : <?php if( $order[‘Template’][‘instances’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘instances’];}?><br/>
Die Styles Special Die Aplicables :<?php if( $order[‘Template’][‘sd_aplicables’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘sd_aplicables’];}?><br/>
Original width(Single/Double) : <?php if( $order[‘Template’][‘original_width_sds’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘original_width_sds’];}?><br/>
Width in Inches :<?php if( $order[‘Template’][‘width_ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘width_ins’];}?><br/>
Height in Inches  :<?php if( $order[‘Template’][‘height_ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘height_ins’];}?><br/>
Estimated Area in inches  :<?php if( $order[‘Template’][‘estimated_area_ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘estimated_area_ins’];}?><br/>
Estimated Area in cms :  :<?php if( $order[‘Template’][‘estimated_area_cms’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘estimated_area_cms’];}?><br/>
Thickness 4ins :<?php if( $order[‘Template’][‘thickness_4ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘thickness_4ins’];}?><br/>
Thickness 6ins :<?php if( $order[‘Template’][‘thickness_6ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘thickness_6ins’];}?><br/>
Thickness 8ins :<?php if( $order[‘Template’][‘thickness_8ins’] ==”){echo “Not Available”;}else {echo $order[‘Template’][‘thickness_8ins’];}?>

<h2>Material Information</h2>

<p>Material Name :<span><?php echo $order[‘Material’][‘name’];?><br/>
Material Price :<span><?php echo $order[‘Material’][‘price’];?><br/>
Material Country Of Origin :<?php if( $order[‘Material’][‘country_of_rigin’] ==”){echo “Not Available”;}else {echo $order[‘Material’][‘country_of_rigin’];}?><br/>
Material Stone Type : <?php echo $order[‘Material’][‘stone_type’];?><br/>
Material Color Tone :<?php echo $order[‘Material’][‘color_tone_#’];?><br/>
Material Instance : <?php echo $order[‘Material’][‘instance’];?><br/>
Material Color Code :<?php echo $order[‘Order’][‘order’];?><br/>


Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s