Monday, April 16, 2012

PDF Creation

PDF Creation:


First we need to download the DOMPDF [Html to Pdf converter] from [http://code.google.com/p/dompdf/].Then keep that folder inside your pdf module.



function pdf_creation_menu(){
  $items['pdf_creation'] = array(
    'page callback' => 'pdf_creation',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
);
  
  return $items;
}


function  pdf_creation () {
//You can add your own HTML or you can print your DB details as a HTML
//You can theme it by default drupal theming and pass that value to this $content
// Ex: $content = theme('create_pdf', $value);
// In this create_pdf tpl you can theme with your own styles,but you need to give the styles inside the same file itself. Like <style>your styles</style> at the top of the tpl file.



$content = '<html><body>'.
  '<p>Put your html here, or generate it with your favourite '.
  'templating system.</p>'.
  '</body></html>'; 


  require_once("dompdf/dompdf_config.inc.php");  //Path to identify the dompdf converter.
  $dompdf = new DOMPDF();
  $dompdf->load_html($content);
  $dompdf->set_paper('letter', 'portrait');
  $dompdf->render();


  $dompdf->stream("pdf_name.pdf");


  exit(0);
}


Finally give this link [pdf_creation] as your PDF downloader link.

No comments:

Post a Comment