TCPDF for getting database values

         $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Salary Slip');
$pdf->SetDisplayMode('real', 'default');
// set default header data

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font

// set margins

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
 $pdf->SetFont('dejavusans', '', 10);
            // Add a page

$htmlcontent = "<head>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
th, td {
    padding: 5px;
    text-align: left;    

<div class='row'>

    <div class='col-lg-12'>
        <section class='panel'>";

            $htmlcontent .= "<div class='panel-heading pull-right'>Issue Date: ". date('M-d-Y') ."</div>";
            $htmlcontent .= "<div class='panel-body'>
                <table style='width:100%'>
                           <th>Emp Role Id :</th>
                           <td>".  $result->id ."</td>
                           <th>Employee Name :</th>
                           <td>" .  $personal->firstname . "</td>";
              $htmlcontent .="
                            <td>" . $prof->department . "</td>
                             <th>Bank Acc/No:</th>
                           <td>" . $other->accno . "</td>";
                 $htmlcontent .="         
                              <td>" . $prof->designation . "</td>
                             <th>PAN No:</th>
                           <td>" . $other->panno . "</td>";
                  $htmlcontent .="         
                            <th>Date Of Birth:</th>
                              <td>" .  $personal->dob . "</td>
                             <th>Date Of Joining:</th>
                           <td>" . $other->doj . "</td>
                  $htmlcontent .="
                <table style='width:100%'>
                            <th>Earnings </th>
                            <th>Amount :</th>
                                <p>House Rent Allowance</p>
                                <p>Conveyance Allowance</p>
                                <p>Advance Statutory Bonus</p>
                                <p>Shift Allowance</p>
                                 <p>Arrear-Taxable Allowance</p>
                                  <p>Other Taxable Allowance</p>
                                   <p>Special Incentive</p>
                                    <p>Arrear Special Incentive</p>
                                     <p>Other Payment</p>
                                <p>" . $earnings->basic . ".00</p>
                                  <p>" . $earnings->hra . ".00</p>
                                 <p>" . $earnings->ca . ".00</p>
                                   <p>" . $earnings->asb . ".00</p>
                                   <p>" . $earnings->shiftallowance . ".00</p>
                                   <p>" . $earnings->arrear . ".00</p>
                                     <p>" . $earnings->otherallowancetax . ".00</p>
                                      <p>" . $earnings->specialincentive . ".00</p>
                                      <p>" . $earnings->arrearspecialincentive . ".00</p>
                                       <p>" . $earnings->otherpayment . ".00</p>
                                <p>Provident Fund</p>
                                <p>Professional Tax</p>
                                <p>Transport Deduction</p>
                                <p>Income Tax</p>
                              <p>" .  $deductions->pf . ".00</p>
                               <p>" . $deductions->ptax . ".00</p>
                               <p>" .   $deductions->transport . ".00</p>
                                 <p>" .   $deductions->incometax . ".00</p>
                            <td>Total Earnings:</td>
                                 <p>" . $earn =( $earnings->basic + 
                                 $earnings->hra +
                                 $earnings->ca +
                                 $earnings->asb +
                                 $earnings->shiftallowance +
                                 $earnings->arrear +
                                 $earnings->otherallowancetax +
                                 $earnings->specialincentive +
                                 $earnings->arrearspecialincentive +
                                 $earnings->otherpayment) . ".00</p>
                            <td>Total Deductions:</td>
                                  <p>" . $ded =( $deductions->pf +
                                          $deductions->ptax +
                                          $deductions->transport +
                                         $deductions->incometax) . ".00</p>
                  $htmlcontent .="
                <table style='width:100%'>
                         <th>Net Pay:</th>
                         <td>Rs." . $net=( $earn - $ded) . ".00</td>
                            <th>In Words.</th>
            <div class='panel-footer'></div>
$pdf->writeHTML($htmlcontent, true, 0, true, 0); ob_clean();
$pdf->Output('slip.pdf', 'I');

only the table headings appear but not php values

@roopam_kaur when you post code in the forum, you need to format it. To do so you can either select all the code and click the </> button, or type 3 backticks ``` on a separate line both before and after the code block.

Can you show the code where the PHP values are created? I can see you using them, but not where they come from. Presumably you have checked to see that they have values in them?

public function generatepdf($employee_id)

$this->data['result'] = $this->salary_m->getEmployeeRecords($employee_id);
                 $this->data['personal'] = $this->salary_m->getPersonalDetails($employee_id);
                    $this->data['earnings'] = $this->salary_m-> getSalaryDetails($employee_id);
   $this->data['deductions'] = $this->salary_m->getDeductionDetails($employee_id);
      $this->data['other'] = $this->salary_m->getOtherDetails($employee_id);
         $this->data['prof'] = $this->salary_m->getProfessionalDetails($employee_id);


having any idea to what is wrong?

Sorry, nothing jumps out.

I’m wondering about variable scope, but I’m not familiar with the method you use to call the code that produces the PDF:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.