Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating PDF file from HTML using DOMPDF in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.28k
    Comment on it

    In order to convert HTML data into a pdf file here are the followings steps you need to follow:

    Step 1: Download the DOMPDF file from Github. here is the link

    https://github.com/dompdf/dompdf

    or you can download from the zip attached at the end of this post

    Step2: After downloading DOMPDF library put it into the app/vendors directory. Make sure the library folder name is dompdf.

    Step:3 In you Controller create a function that will use the DOMPDF library.

    public function htmltopdf(){
            App::import('Vendor', 'dompdf', array('file' => 'dompdf' . DS . 'dompdf_config.inc.php'));
    
            $html =
            '<html><body>'.
            '<p>Put your html here, or generate it with your favourite '.
            'templating system.</p>'.
            '</body></html>';
    
            $dompdf = new DOMPDF();
            $papersize = 'legal';
            $orientation = 'landscape';
            $dompdf->load_html($html);
            $dompdf->set_paper($papersize, $orientation);
            $dompdf->render();
            echo $dompdf->output();
            $output = $dompdf->output();
            file_put_contents('Brochure.pdf', $output);
        }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: