PHP code example of rafsalvioni / zeus-barcode

1. Go to this page and download the library: Download rafsalvioni/zeus-barcode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rafsalvioni / zeus-barcode example snippets




use Zeus\Barcode\Codabar;
use Zeus\Barcode\Renderer\SvgRenderer;

$bc = new Codabar('A123456B');
$renderer = new SvgRenderer();
$bc->draw($renderer)->render();



use Zeus\Barcode\Upc\Ean13;

// We don't know the checksum digit, so, we gave false to second argument
$bc = new Ean13('123456789098', false);
echo $bc->getChecksum(); // Prints "2"

// Now we already know the checksum. Let's check it:
$bc = new Ean13('1234567890982', true);
echo $bc->getChecksum(); // Prints "2"

// Let's give a wrong checksum digit
try {
    $bc = new Ean13('1234567890983');
}
catch (\Zeus\Barcode\Exception $ex) {
    echo $ex->getMessage();
}



use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

// With default width
$bc1 = new Interleaved('5236589', false);
// Changing widths
$bc2 = clone $bc1;
$bc2->setNarrowWidth(2)->setWideWidth(6);

$renderer->stream($bc1)
         ->stream($bc2)
         ->render();



use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

$bc = new Interleaved('5236589', false);
$bc->backColor = 0xffffaa;
$bc->foreColor = 0x0000ff;
$bc->barwidth  = 2;
$bc->barheight = 150;
$bc->fontsize  = 5;

$bc->draw($renderer)->render();



use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

$bc = new Interleaved('5236589', false);
$bc->backColor = 0xffffaa;
$bc->foreColor = 0x0000ff;
$bc->barwidth  = 2;
$bc->barheight = 150;
$bc->fontsize  = 5;

$renderer->offsetTop = 50;
$renderer->offsetLeft = 50;
$renderer->backColor = 0xababab;

$bc->draw($renderer)->render();



use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$renderer = new SvgRenderer();

$bc = new Interleaved('5236589', false);
$bc->backColor = 0xffffaa;
$bc->foreColor = 0x0000ff;
$bc->barwidth  = 2;
$bc->barheight = 150;
$bc->fontsize  = 5;

// Setting render to merge mode
$renderer->merge = true;

$renderer->offsetTop = 50;
$renderer->offsetLeft = 50;
$renderer->backColor = 0xababab;

$bc2 = clone $bc;
$bc2->backColor = 0xffffff;

$bc->draw($renderer); // Draw barcode 1
$renderer->offsetLeft += $bc->getTotalWidth() + 20; // Add a offset
$bc2->draw($renderer);  // Draw barcode 2
$renderer->render(); // Show the result



use Zeus\Barcode\Code2of5\Interleaved;
use Zeus\Barcode\Renderer\SvgRenderer;

$bc = new Interleaved('5236589', false);

$renderer = new SvgRenderer();
$renderer->setResource("<\DOMDocument OBJECT, XML FILE OR XML STRING>");
$renderer->offsetLeft = 50;
$renderer->offsetTop = 50;

$bc->draw($renderer)->render();