Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Html to pdf conversion in cakephp

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 922
    Comment on it

    Step1- For converting html to pdf  first we have to download dompdf, then we have to  extract it and  put it into /app/Vendor.

    Step2- Then we have to import this dompdf folder and its file by using below code in our controller.

    App::import('Vendor', 'dompdf',array('file'=>'dompdf/'));

    step3- Then we have to create view which contain link on which we click, it will converts html to pdf.

    Our view contain below code:-

     <?php echo $this->Html->link('DomPdf',array('controller'=>'Users','action'=>'dompdf'));

    step4- Then we have to create function in our controller which contain the logic for html to pdf conversion.

     public function dompdf(){
              $dompdf =  new DOMPDF();
                $result = $this->User->find('all');
                $html1= "";
                foreach ($result as $value) {
                    $html1 = $html1."<tr><td>".$value['User']['id']."</td>
                $html = '<html>
                <p>Users List:</p>
                <table border=1>
                <th>Phone No:</th>
                <th>Email Id</th>
              $output = $dompdf->output();
              file_put_contents("file.pdf", $output);

    In above code we our fetching data from our database then converting that data into html then converting it into pdf.

 1 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: