Zend_Barcode Objects
Barcode objects allow you to generate barcodes independently of the rendering support. After
generation, you can retrieve the barcode as an array of drawing instructions that you can
provide to a renderer.
Objects have a large number of options. Most of them are common to all objects. These
options can be set in four ways:
As an array or a Zend_Config object passed to the
constructor.
As an array passed to the setOptions() method.
As a Zend_Config object passed to the
setConfig() method.
Via individual setters for each configuration type.Different ways to parameterize a barcode object 'ZEND-FRAMEWORK', 'barHeight' => 40);
// Case 1: constructor
$barcode = new Zend_Barcode_Object_Code39($options);
// Case 2: setOptions()
$barcode = new Zend_Barcode_Object_Code39();
$barcode->setOptions($options);
// Case 3: setConfig()
$config = new Zend_Config($options);
$barcode = new Zend_Barcode_Object_Code39();
$barcode->setConfig($config);
// Case 4: individual setters
$barcode = new Zend_Barcode_Object_Code39();
$barcode->setText('ZEND-FRAMEWORK')
->setBarHeight(40);
]]>Common Options
In the following list, the values have no units; we will use the term "unit." For
example, the default value of the "thin bar" is "1 unit". The real units depend on the
rendering support (see the renderers
documentation for more information). Setters are each named by uppercasing
the initial letter of the option and prefixing the name with "set" (e.g. "barHeight"
becomes "setBarHeight"). All options have a corresponding getter prefixed with "get"
(e.g. "getBarHeight"). Available options are:
Common OptionsOptionData TypeDefault ValueDescriptionbarcodeNamespaceStringZend_Barcode_Object
Namespace of the barcode; for example, if you need to extend the
embedding objects
barHeightInteger50Height of the barsbarThickWidthInteger3Width of the thick barbarThinWidthInteger1Width of the thinfactorInteger, Float,
String or Boolean1Factor by which to multiply bar widths and font sizesforeColorInteger0 (black)
Color of the bar and the text. Could be provided as an integer
or as a HTML value (e.g. "#333333")
backgroundColorInteger or String16777125 (white)
Color of the background. Could be provided as an integer
or as a HTML value (e.g. "#333333")
reverseColorBooleanFALSEAllow switching the color of the bar and the backgroundorientationInteger, Float,
String or Boolean0Orientation of the barcodefontString or IntegerNULL
Font path to a TTF font or a number between 1 and 5
if using image generation with GD (internal fonts)
fontSizeInteger10Size of the font (not applicable with numeric fonts)withBorderBooleanFALSEDraw a border around the barcode and the quiet zoneswithQuietZonesBooleanTRUELeave a quiet zone before and after the barcodedrawTextBooleanTRUESet if the text is displayed below the barcodestretchTextBooleanFALSESpecify if the text is stretched all along the barcodewithChecksumBooleanFALSE
Indicate whether or not the checksum is automatically added to
the barcode
withChecksumInTextBooleanFALSE
Indicate whether or not the checksum is displayed in the textual
representation
textStringNULLThe text to represent as a barcode
Particular case of static setBarcodeFont()
You can set a commont font for all your objects by using the static method
Zend_Barcode_Object::setBarcodeFont(). This value
can be always be overridden for individual objects by using the
setFont() method.
'ZEND-FRAMEWORK')
); // will use 'my_font.ttf'
// or:
Zend_Barcode::render(
'code39',
'image',
array(
'text' => 'ZEND-FRAMEWORK',
'font' => 3
)
); // will use the 3rd GD internal font
]]>Common Additional Getters
Common GettersGetterData TypeDescriptiongetType()String
Return the name of the barcode class without the namespace (e.g.
Zend_Barcode_Object_Code39 returns simply
"code39")
getRawText()StringReturn the original text provided to the objectgetTextToDisplay()String
Return the text to display, including, if activated, the checksum value
getQuietZone()Integer
Return the size of the space needed before and after the barcode
without any drawing
getInstructions()ArrayReturn drawing instructions as an array.getHeight($recalculate = false)Integer
Return the height of the barcode calculated after possible rotation
getWidth($recalculate = false)Integer
Return the width of the barcode calculated after possible rotation
getOffsetTop($recalculate = false)Integer
Return the position of the top of the barcode calculated after
possible rotation
getOffsetLeft($recalculate = false)Integer
Return the position of the left of the barcode calculated after
possible rotation