Hello Experts,

I have to get data from a table and print it on page and also have to print a barcode image based on a field value, following is the code, but the error is that it shows everything as image, but if I remove the header content-type then everything shown as text.

Please help me.

PHP Code:
<?php
// Including all required classes
require_once('class/BCGFontFile.php');
require_once(
'class/BCGColor.php');
require_once(
'class/BCGDrawing.php');
require_once(
"dbConnect.php");

// Including the barcode technology
require_once('class/BCGcode39.barcode.php');

// Loading Font
$font = new BCGFontFile('./class/font/Arial.ttf'12);
//Data
$classID $_POST['txtclassID'];
$RollNo $_POST['D1'];
$cDate $_POST['cDate'];
$RNumber $_POST['RNumber'];
$Amount $_POST['Amount'];
$forMonth $_POST['FormonthOf'];
$AccountOf $_POST['AccountOf'];
$Desc $_POST['Desc'];
$cCode=$_POST['cCode'];
//Data
$sql=mysql_query("select * from class where classID='$classID'");
$row mysql_fetch_assoc($sql);
$class $row['class'];
$section=$row['section'];
$session=$row['session'];
$sql2mysql_query("select studName from biodata where rollnum='$RollNo'");
$row2=mysql_fetch_assoc($sql2);
$name $row2['studName'];
// The arguments are R, G, B for color.
$color_black = new BCGColor(000);
$color_white = new BCGColor(255255255);

$drawException null;
try {
    
$code = new BCGcode39();
    
$code->setScale(2); // Resolution
    
$code->setThickness(30); // Thickness
    
$code->setForegroundColor($color_black); // Color of bars
    
$code->setBackgroundColor($color_white); // Color of spaces
    
$code->setFont($font); // Font (or 0)
    
$code->parse($cCode); // Text
} catch(Exception $exception) {
    
$drawException $exception;
}

/* Here is the list of the arguments
1 - Filename (empty : display on screen)
2 - Background color */
$drawing = new BCGDrawing(''$color_white);
if(
$drawException) {
    
$drawing->drawException($drawException);
} else {
    
//  Receipt
 
echo '   <table border="0" width="50%" cellspacing="0" cellpadding="0">
    <tr>
        <td style="border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px">
        <p align="center"><b><u><font size="5">ANSI School &amp; Degree College 
        Mardan<br>
        </font></u><font size="4">Payment Receipt</font></b></td>
    </tr>
    <tr>
        <td>
        <table border="1" width="100%">
            <tr>
                <td width="79"><b>Session:</b></td>
                <td width="133">'
.$session.'</td>
                <td width="68"><b>Date:</b></td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td width="79"><b>Class:</b></td>
                <td width="133">'
.$class.'</td>
                <td width="68"><b>Section:</b></td>
                <td>'
.$session.'</td>
            </tr>
            <tr>
                <td width="79"><b>RollNo:</b></td>
                <td width="133">'
.$RollNo.'</td>
                <td width="68"><b>Name:</b></td>
                <td>'
.$name.'</td>
            </tr>
            <tr>
                <td width="79"><b>Amount:</b></td>
                <td width="133">'
.$Amount.'</td>
                <td width="68">For Month</td>
                <td>'
.$forMonth.'</td>
            </tr>
            <tr>
                <td width="79"><b>on Account:</b></td>
                <td width="133">'
.$AccountOf.'</td>
                <td width="68"><b>Desc</b></td>
                <td>'
.$Desc.'</td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
        <td>'
;
              
$drawing->setBarcode($code);
                
$drawing->draw();
    echo 
'</td>
    </tr>
    <tr>
        <td><font color="#666666">Note: Errors and omissions excepted.</font></td>
    </tr>
</table>'
;

 }

// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');

// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>
<p align="center">
<a href="javascript:window.print()">
<img src="images/print.jpg" border="0" width="81" height="32" /></a> 
</p>