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
    • 1.39k
    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

    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 . ''));
            $html =
            '<p>Put your html here, or generate it with your favourite '.
            'templating system.</p>'.
            $dompdf = new DOMPDF();
            $papersize = 'legal';
            $orientation = 'landscape';
            $dompdf->set_paper($papersize, $orientation);
            echo $dompdf->output();
            $output = $dompdf->output();
            file_put_contents('Brochure.pdf', $output);


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