SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Finland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FPDF, attaching barcode

    Hi

    Im trying to attach barcode image to pdf file, but strangely same image appears on every page although bcode string changes as wanted. Anyone knows whys that? I'll put one function that takes pdf file and barcode string as arguments.

    - first delete old image
    - initialize barcode
    - collect image data to buffer
    - write binary data to image file
    - attach image source to pdf
    - attach bar code string to pdf and return pdf

    Should be straight forward...

    PHP Code:
    function setBarCode$pdf$bcode ) {
        global 
    $_x$_y;
        
    $img_src 'code.png';
        
    unlink$img_src );
        
    // MAKE BARCODE
        
    $c = new Image_Barcode_code128();

        
    $c->_barcodeheight 83;
        
    $c->_font 3;  
        
    $c->_barwidth 2;
        
        
    ob_start(); 
        
    $c->draw$bcode'png'false );
        
    $image_data ob_get_contents();
        
    ob_end_clean();
        
        
    $fp fopen$img_src'wb');
        
    fwrite$fp$image_data ) ;
        
    fclose$fp );
        
    // ATTACH BARCODE TO PDF
        
    $pdf->Image$img_src$_x+5$_y+85 );
        
    // print code
        
    $pdf->SetFont'Arial''B');
        
    $pdf->SetXY$_x+55$_y+76.7 );
        
    $pdf->Cell10013$bcode );
        
    $pdf->SetXY$_x+55$_y+109.5 );
        
    $pdf->Cell10013$bcode );
        return 
    $pdf;

    Perhaps image content comes from cache? Anything to do with it?

    Well i tried this formula

    Code:
    header( 'Cache-Control: no-cache, must-revalidate' );
    header( 'Expires: '.gmdate( 'D, d M Y H:i:s', time() - 60*60*24*7 ).' GMT' );
    header( 'Last-Modified: '.gmdate( 'D, d M Y H:i:s', time() ).' GMT' );
    header( 'Content-Length: '.ob_get_length() );
    but it didn't make the trick.
    Last edited by pht; Nov 16, 2005 at 07:50.

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Finland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quick solution was to save image file with name build from bcode, when it is unique every time... still like to know, why system could not write and get new image every time function was called...


Bookmarks

Posting Permissions

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