Zend\Barcode Renderers

Renderers have some common options. These options can be set in three ways:

  • As an array or a Traversable object passed to the constructor.
  • As an array passed to the setOptions() method.
  • As discrete values passed to individual setters.

Different ways to parameterize a renderer object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
use Zend\Barcode\Renderer;

$options = array('topOffset' => 10);

// Case 1
$renderer = new Renderer\Pdf($options);

// Case 2
$renderer = new Renderer\Pdf();
$renderer->setOptions($options);

// Case 3
$renderer = new Renderer\Pdf();
$renderer->setTopOffset(10);

Common Options

In the following list, the values have no unit; 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. The individual setters are obtained by uppercasing the initial letter of the option and prefixing the name with “set” (e.g. “barHeight” => “setBarHeight”). All options have a correspondent getter prefixed with “get” (e.g. “getBarHeight”). Available options are:

Common Options
Option Data Type Default Value Description
rendererNamespace String Zend\Barcode\Renderer Namespace of the renderer; for example, if you need to extend the renderers
horizontalPosition String “left” Can be “left”, “center” or “right”. Can be useful with PDF or if the setWidth() method is used with an image renderer.
verticalPosition String “top” Can be “top”, “middle” or “bottom”. Can be useful with PDF or if the setHeight() method is used with an image renderer.
leftOffset Integer 0 Top position of the barcode inside the renderer. If used, this value will override the “horizontalPosition” option.
topOffset Integer 0 Top position of the barcode inside the renderer. If used, this value will override the “verticalPosition” option.
automaticRenderError Boolean FALSE Whether or not to automatically render errors. If an exception occurs, the provided barcode object will be replaced with an Error representation. Note that some errors (or exceptions) can not be rendered.
moduleSize Float 1 Size of a rendering module in the support.
barcode Zend\Barcode\Object NULL The barcode object to render.

An additional getter exists: getType(). It returns the name of the renderer class without the namespace (e.g. Zend\Barcode\Renderer\Image returns “image”).

Zend\Barcode\Renderer\Image

The Image renderer will draw the instruction list of the barcode object in an image resource. The component requires the GD extension. The default width of a module is 1 pixel.

Available options are:

Zend\Barcode\Renderer\Image Options
Option Data Type Default Value Description
height Integer 0 Allow you to specify the height of the result image. If “0”, the height will be calculated by the barcode object.
width Integer 0 Allow you to specify the width of the result image. If “0”, the width will be calculated by the barcode object.
imageType String “png” Specify the image format. Can be “png”, “jpeg”, “jpg” or “gif”.

Zend\Barcode\Renderer\Pdf

The PDF renderer will draw the instruction list of the barcode object in a PDF document. The default width of a module is 0.5 point.

There are no particular options for this renderer.

Table Of Contents

Previous topic

Zend\Barcode\Barcode Objects

Next topic

Zend\Cache\Storage\Adapter

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Barcode Renderers on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.