/**
 * Created by PhpStorm.
 * User: wenzi
 * Date: 11/26/13
 * Time: 3:51 PM
 */
function generate_barcode($text, $file_name)
{
    // Including all required classes
    require_once 'barcode/class/BCGFontFile.php';
    require_once 'barcode/class/BCGColor.php';
    require_once 'barcode/class/BCGDrawing.php';
    // Including the barcode technology
    require_once 'barcode/class/BCGcode39.barcode.php';
    // Loading Font
    $CURRENT_TEMPLATE_URL = dirname(Yii::app()->basePath) . Yii::app()->params['THEME_BASE_URL'];
    $font = new BCGFontFile($CURRENT_TEMPLATE_URL . '/fonts/helvetica_neue_thin.ttf', 18);
    // The arguments are R, G, B for color.
    $color_black = new BCGColor(0, 0, 0);
    $color_white = new BCGColor(255, 255, 255);
    $drawException = null;
    try {
        $code = new BCGcode39();
        $code->setScale(2);
        // Resolution
        $code->setThickness(40);
        // Thickness
        $code->setForegroundColor($color_black);
        // Color of bars
        $code->setBackgroundColor($color_white);
        // Color of spaces
        $code->setFont($font);
        // Font (or 0)
        $code->parse($text);
        // Text
        $code->clearLabels();
    } catch (Exception $exception) {
        $drawException = $exception;
    }
    /* Here is the list of the arguments
       1 - Filename (empty : display on screen)
       2 - Background color */
    $drawing = new BCGDrawing($file_name, $color_white);
    if ($drawException) {
        $drawing->drawException($drawException);
    } else {
        $drawing->setBarcode($code);
        $drawing->draw();
    }
    // Draw (or save) the image into PNG format.
    $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
}
 public static function imprimir()
 {
     $cracha = new Cracha();
     $cracha->selecionarPorId($_GET['id']);
     $color_black = new BCGColor(0, 0, 0);
     $color_white = new BCGColor(255, 255, 255);
     $font = new BCGFontFile(__DIR__ . '/../components/barcodegen/font/Arial.ttf', 18);
     $code = new BCGcode39();
     // Or another class name from the manual
     $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(str_pad($_GET['id'], 4, "0", STR_PAD_LEFT));
     // Text
     $code->clearLabels();
     ob_start();
     $drawing = new BCGDrawing('', $color_white);
     $drawing->setBarcode($code);
     $drawing->draw();
     header('Content-Type: image/png');
     $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
     $codigoDeBarras = ob_get_contents();
     ob_end_clean();
     header('Content-Type: text/html;');
     self::$variaveis = array('cracha' => $cracha, 'codigoDeBarras' => $codigoDeBarras);
     self::$header = '';
     self::$topo = '';
     self::$menu = '';
     self::$corpo = 'imprimir';
     self::$footer = '';
     self::renderizar(self::$viewController);
 }
Beispiel #3
0
$stmt->execute();
while ($employee = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $code = new BCGcode39();
    // Or another class name from the manual
    $code->setScale(2);
    // Resolution
    $code->setThickness(30);
    // Thickness
    $code->setForegroundColor($colorFont);
    // Color of bars
    $code->setBackgroundColor($colorBack);
    // Color of spaces
    $code->setFont($font);
    // Font (or 0)
    $code->parse($employee['code']);
    $code->clearLabels();
    $drawing = new BCGDrawing('', $colorBack);
    $drawing->setFilename('./barcodes/' . $employee['name'] . '.png');
    $drawing->setBarcode($code);
    $drawing->draw();
    $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
}
die;
$emp_codes = array('11506025', '19810002', '11404011', '11105007', '10907001', '19411001', '11302006');
$count = 0;
foreach ($emp_codes as $number) {
    $code = new BCGcode39();
    // Or another class name from the manual
    $code->setScale(2);
    // Resolution
    $code->setThickness(30);