PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

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:

Table 14. Common Options

Option Data Type Default Value Description
barcodeNamespace String Zend_Barcode_Object Namespace of the barcode; for example, if you need to extend the embedding objects
barHeight Integer 50 Height of the bars
barThickWidth Integer 3 Width of the thick bar
barThinWidth Integer 1 Width of the thin
factor Integer 1 Factor by which to multiply bar widths and font sizes
foreColor Integer 0 (black) Color of the bar and the text. Could be provided as an integer or as a HTML value (e.g. "#333333")
backgroundColor Integer or String 16777125 (white) Color of the background. Could be provided as an integer or as a HTML value (e.g. "#333333")
reverseColor Boolean FALSE Allow switching the color of the bar and the background
orientation Integer 0 Orientation of the barcode
font String or Integer NULL Font path to a TTF font or a number between 1 and 5 if using image generation with GD (internal fonts)
fontSize Integer 10 Size of the font (not applicable with numeric fonts)
withBorder Boolean FALSE Draw a border around the barcode and the quiet zones
withQuietZones Boolean TRUE Leave a quiet zone before and after the barcode
drawText Boolean TRUE Set if the text is displayed below the barcode
stretchText Boolean FALSE Specify if the text is stretched all along the barcode
withChecksum Boolean FALSE Indicate whether or not the checksum is automatically added to the barcode
withChecksumInText Boolean FALSE Indicate whether or not the checksum is displayed in the textual representation
text String NULL The 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.

<?php
// In your bootstrap:
Zend_Barcode_Object::setBarcodeFont('my_font.ttf');

// Later in your code:
Zend_Barcode::render(
    
'code39',
    
'pdf',
    array(
'text' => '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

Zend Framework