• How To Print Pdf In A Drupal Custom Module & Print Barcode In The Bottom Of The Pdf?

    Module: print_pdf  
    Menu Callback Function        : print_pdf_menu()
    Access Permission Function  : print_pdf_permission()

    Form                                       : print_pdf_form()

    <?php
    function print_pdf_menu() {
      $items = array();
      $items['print_pdf'] = array(
        'title' => 'Download PDF', //page title
        'description' => 'Download PDF File ',
        'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed.  for a form, use drupal_get_form
        'page arguments' => array('print_pdf_form'), //put the name of the form here
        //'access callback' => TRUE ,
                'access arguments' => array('Download PDF'),
      );
      return $items;
    }
    function print_pdf_permission()
    {
        return array(
            'Download PDF' =>  array('title' => t('Download PDF')),
        );   
    }
    function print_pdf_form($form, &$form_state)
    {
    //print barcode also
    $html=”<table style='border:2px solid'><tr><td>Test pdf </td></tr></table><div> Code39 : <barcode code='9865457216' type='C39' size='0.5' height='2.0' /></div>
    <div> ISBN : <barcode code='1234567890' type='isbn' size='0.5' height='2.0' /></div>
    <div> Code93 : <barcode code='987654321' type='c93' size='0.5' height='2.0' /></div>”;
    include ("sites/all/modules/mpdf/mpdf.php");
    $current_date=format_date(time(), 'custom', 'Y-m-d h:i:sA ');
    $mpdf=new mPDF('win-1252','A4','','','14','14','18','14');
    $mpdf->SetDisplayMode('fullpage');
    $mpdf->list_indent_first_level = 0;
    //$stylesheet = file_get_contents('sites/all/modules/mpdf/examples/mpdfstyleA4.css');
    $mpdf->mirrorMargins = 1;
    //To print url & current date in header
    $mpdf->SetHTMLHeader('<div style="text-align: right;float:left;">'.$current_date.'&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;'.$base_url.'</div>', 'O');
    $mpdf->defaultPageNumStyle = '1';
    $mpdf->setFooter('<div style="text-align: right;font-size:18px;font-style: italic;">{PAGENO}</div>');
    //$mpdf->WriteHTML($stylesheet,1);
    $mpdf->WriteHTML($html);
    $mpdf->debug = true;
    $mpdf->Output("test.pdf",'D');
      return $form; 
    }
  • You might also like

    No comments:

    Post a Comment