www.webdeveloper.com
Results 1 to 11 of 11

Thread: [RESOLVED] Show BarCode Image along with text

  1. #1
    Join Date
    Apr 2009
    Posts
    73

    resolved [RESOLVED] Show BarCode Image along with text

    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>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    You have to make a separate script whose only purpose is to display the image, then call that script from the src attribute of the relevant img tag. (A typical practice is to have the image url include some sort of ID in the query string that the image-server script uses to determine what to draw.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2009
    Posts
    73
    I tried the below method but it doesn't work.and I have no other idea to do it.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta name="author" content="Naveed" />

        <title>Make Receipt</title>
    </head>
    <body>
    <?php

        
    //  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>'
    ;
                 
    $id $cCode;
                 include(
    'testBarCode.php');
        echo 
    '</td>
        </tr>
        <tr>
            <td><font color="#666666">Note: Errors and omissions excepted.</font></td>
        </tr>
    </table>'
    ;

     
    ?>
    <p align="center">
    <a href="javascript:window.print()">
    <img src="images/print.jpg" border="0" width="81" height="32" /></a> 
    </p>
    </body>
    </html>
    ...

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

    // Including the barcode technology
    require_once('class/BCGcode39.barcode.php');
    $cCode=$_REQUEST['id'];
    // Loading Font
    $font = new BCGFontFile('./class/font/Arial.ttf'12);

    // 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(20); // 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 {
        
    $drawing->setBarcode($code);
        
    $drawing->draw();
     }

    // 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);
    ?>

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    include('testBarCode.php');
    PHP Code:
    <img src="testBarCode.php" /> 

  5. #5
    Join Date
    Apr 2009
    Posts
    73
    Thanks dear it worked, but how to pass arguments to this testBarCode.php, can u please help.

  6. #6
    Join Date
    Apr 2009
    Posts
    73
    Thanks alot, it workd.

  7. #7
    Join Date
    Nov 2012
    Posts
    4

  8. #8
    Join Date
    Nov 2012
    Posts
    4
    Generate QR-Code and encode barcode to png format
    qrcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png
    qrcode.drawBarcode("C://vbnet-qrcode.png")

    ' Print QR-Code to vb.net Bitmap object
    Dim qrcodeBitmap As Bitmap
    qrcodeBitmap = qrcode.drawBarcode()

  9. #9
    Join Date
    Dec 2013
    Posts
    5
    Quote Originally Posted by collins hall View Post
    Generate QR-Code and encode barcode to png format
    qrcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png
    qrcode.drawBarcode("C://vbnet-qrcode.png")

    ' Print QR-Code to vb.net Bitmap object
    Dim qrcodeBitmap As Bitmap
    qrcodeBitmap = qrcode.drawBarcode()
    Quite helpful. Thanks for the solution!

  10. #10
    Join Date
    Aug 2013
    Posts
    30
    Quote Originally Posted by collins hall View Post
    Generate QR-Code and encode barcode to png format
    qrcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png
    qrcode.drawBarcode("C://vbnet-qrcode.png")

    ' Print QR-Code to vb.net Bitmap object
    Dim qrcodeBitmap As Bitmap
    qrcodeBitmap = qrcode.drawBarcode()
    only to png format ?

  11. #11
    Join Date
    Jun 2014
    Posts
    2
    I think that I have the exact same question like what cindy313 mentioned above. Sounds like that java qr code generation is not an easy thing.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles