Zend_Barcode-Creation.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.barcode.creation">
  4. <title>Barcode creation using Zend_Barcode class</title>
  5. <sect2 id="zend.barcode.creation.configuration">
  6. <title>Using Zend_Barcode::factory</title>
  7. <para>
  8. <classname>Zend_Barcode</classname> uses a factory method to create an instance of a
  9. renderer that extends <classname>Zend_Barcode_Renderer_RendererAbstract</classname>. The
  10. factory method accepts five arguments.
  11. </para>
  12. <orderedlist>
  13. <listitem>
  14. <para>The name of the barcode format (e.g., "code39") (required)</para>
  15. </listitem>
  16. <listitem>
  17. <para>The name of the renderer (e.g., "image") (required)</para>
  18. </listitem>
  19. <listitem>
  20. <para>
  21. Options to pass to the barcode object (an array or
  22. <classname>Zend_Config</classname> object) (optional)
  23. </para>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. Options to pass to the renderer object (an array or
  28. <classname>Zend_Config</classname> object) (optional)
  29. </para>
  30. </listitem>
  31. <listitem>
  32. <para>
  33. Boolean to indicate whether or not to automatically render errors. If an
  34. exception occurs, the provided barcode object will be replaced with an Error
  35. representation (optional default <constant>TRUE</constant>)
  36. </para>
  37. </listitem>
  38. </orderedlist>
  39. <example id="zend.barcode.creation.configuration.example-1">
  40. <title>Getting a Renderer with Zend_Barcode::factory()</title>
  41. <para>
  42. <methodname>Zend_Barcode::factory()</methodname> instantiates barcode objects and
  43. renderers and ties them together. In this first example, we will use the
  44. <emphasis>Code39</emphasis> barcode type together with the
  45. <emphasis>Image</emphasis> renderer.
  46. </para>
  47. <programlisting language="php"><![CDATA[
  48. // Only the text to draw is required
  49. $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
  50. // No required options
  51. $rendererOptions = array();
  52. $renderer = Zend_Barcode::factory(
  53. 'code39', 'image', $barcodeOptions, $rendererOptions
  54. );
  55. ]]></programlisting>
  56. </example>
  57. <example id="zend.barcode.creation.configuration.example-2">
  58. <title>Using Zend_Barcode::factory() with Zend_Config objects</title>
  59. <para>
  60. You may pass a <classname>Zend_Config</classname> object to the factory in order to
  61. create the necessary objects. The following example is functionally equivalent to
  62. the previous.
  63. </para>
  64. <programlisting language="php"><![CDATA[
  65. // Using only one Zend_Config object
  66. $config = new Zend_Config(array(
  67. 'barcode' => 'code39',
  68. 'barcodeParams' => array('text' => 'ZEND-FRAMEWORK'),
  69. 'renderer' => 'image',
  70. 'rendererParams' => array('imageType' => 'gif'),
  71. ));
  72. $renderer = Zend_Barcode::factory($config);
  73. ]]></programlisting>
  74. </example>
  75. </sect2>
  76. <sect2 id="zend.barcode.creation.drawing">
  77. <title>Drawing a barcode</title>
  78. <para>
  79. When you <emphasis>draw</emphasis> the barcode, you retrieve the resource in which the
  80. barcode is drawn. To draw a barcode, you can call the <methodname>draw()</methodname> of
  81. the renderer, or simply use the proxy method provided by
  82. <classname>Zend_Barcode</classname>.
  83. </para>
  84. <example id="zend.barcode.creation.drawing.example-1">
  85. <title>Drawing a barcode with the renderer object</title>
  86. <programlisting language="php"><![CDATA[
  87. // Only the text to draw is required
  88. $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
  89. // No required options
  90. $rendererOptions = array();
  91. // Draw the barcode in a new image,
  92. $imageResource = Zend_Barcode::factory(
  93. 'code39', 'image', $barcodeOptions, $rendererOptions
  94. )->draw();
  95. ]]></programlisting>
  96. </example>
  97. <example id="zend.barcode.creation.drawing.example-2">
  98. <title>Drawing a barcode with Zend_Barcode::draw()</title>
  99. <programlisting language="php"><![CDATA[
  100. // Only the text to draw is required
  101. $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
  102. // No required options
  103. $rendererOptions = array();
  104. // Draw the barcode in a new image,
  105. $imageResource = Zend_Barcode::draw(
  106. 'code39', 'image', $barcodeOptions, $rendererOptions
  107. );
  108. ]]></programlisting>
  109. </example>
  110. </sect2>
  111. <sect2 id="zend.barcode.creation.renderering">
  112. <title>Renderering a barcode</title>
  113. <para>
  114. When you render a barcode, you draw the barcode, you send the headers and you send the
  115. resource (e.g. to a browser). To render a barcode, you can call the
  116. <methodname>render()</methodname> method of the renderer or simply use the proxy method
  117. provided by <classname>Zend_Barcode</classname>.
  118. </para>
  119. <example id="zend.barcode.creation.renderering.example-1">
  120. <title>Renderering a barcode with the renderer object</title>
  121. <programlisting language="php"><![CDATA[
  122. // Only the text to draw is required
  123. $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
  124. // No required options
  125. $rendererOptions = array();
  126. // Draw the barcode in a new image,
  127. // send the headers and the image
  128. Zend_Barcode::factory(
  129. 'code39', 'image', $barcodeOptions, $rendererOptions
  130. )->render();
  131. ]]></programlisting>
  132. <para>
  133. This will generate this barcode:
  134. </para>
  135. <para>
  136. <inlinegraphic width="275" align="center" valign="middle"
  137. fileref="figures/zend.barcode.introduction.example-1.png" format="PNG"/>
  138. </para>
  139. </example>
  140. <example id="zend.barcode.creation.renderering.example-2">
  141. <title>Renderering a barcode with Zend_Barcode::render()</title>
  142. <programlisting language="php"><![CDATA[
  143. // Only the text to draw is required
  144. $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
  145. // No required options
  146. $rendererOptions = array();
  147. // Draw the barcode in a new image,
  148. // send the headers and the image
  149. Zend_Barcode::render(
  150. 'code39', 'image', $barcodeOptions, $rendererOptions
  151. );
  152. ]]></programlisting>
  153. <para>
  154. This will generate the same barcode as the previous example.
  155. </para>
  156. </example>
  157. </sect2>
  158. </sect1>