Showing posts with label html to pdf. Show all posts
Showing posts with label html to pdf. Show all posts

Saturday, July 9, 2011

read html file using url and create pdf

hello all,

this is my first technical blog.
It about read html templet and creat pdf from it using html2pdf creater in php.

 function getPDFContent($url , $pdf_name)

    $pdf=new HTML2FPDF();
    $pdf->AddPage();
     $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,$url);
    curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,20);
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);
      if (empty($buffer))
    {
          print "Sorry, Your page not loaded successfully.<p>";
    }
    else
    {
         $pdf->WriteHTML(utf8_decode($buffer));
        $pdf->Output($pdf_name);
    }
}

this function use to create pdf.
you have to pass full path of html file  and file name which you want to name your pdf .
that's it ,now your pdf is present in your current files path.

thanks
naresh