PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/jpgraph/docs/chunkhtml/ch25s02.html

https://code.google.com/
HTML | 477 lines | 458 code | 19 blank | 0 comment | 0 complexity | 7cf78bcac1987bce8bab1024a9c7e1aa MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-2.0, LGPL-2.1, LGPL-3.0
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>25.2. Creating barcodes</title><link rel="stylesheet" href="manual.css" type="text/css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.74.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch25.html" title="Chapter 25. Datamatrix (2D-Barcode)"><link rel="prev" href="ch25.html" title="Chapter 25. Datamatrix (2D-Barcode)"><link rel="next" href="ch25s03.html" title="25.3. Example script"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">25.2. Creating barcodes</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch25.html">Prev</a> </td><th width="60%" align="center">Chapter 25. Datamatrix (2D-Barcode)</th><td width="20%" align="right"> <a accesskey="n" href="ch25s03.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2614278"></a>25.2. Creating barcodes</h2></div></div></div><p>In order to use datamatrix barcodes the module
  2. "<code class="filename">datamatrix/datamatrix.inc.php</code>" must first be included.</p><p>Usage of Datamatrix barcodes follows a similar schema as for the linear and PDF417
  3. barcodes with concepts of an encoder and backend. The principle of the overall
  4. encodation process is shown in <a class="xref" href="ch25s02.html#fig.datamatrix-encodation-principle" title="Figure 25.4. Datamatrix encodation principle">Figure 25.4</a></p><div class="figure"><a name="fig.datamatrix-encodation-principle"></a><p class="title"><b>Figure 25.4. Datamatrix encodation principle</b></p><div class="figure-contents"><div class="mediaobject"><img src="images/datamatrix-encodation-principle.png" alt="Datamatrix encodation principle"></div></div></div><br class="figure-break"><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2614329"></a>25.2.1. Getting started</h3></div></div></div><p>Assuming that the library is installed where it can be found by PHP it is now very
  5. simple to create a basic Data Matrix symbol using just default values. We first show
  6. the complete first example and then discuss it. In the following scripts we will
  7. assume that the include path has the core JpGraph directory in its path.</p><p>All barcode creation follows the following basic three steps :</p><p>
  8. </p><div class="orderedlist"><ol type="1"><li><p>Create an instance of the encoder with the chosen datamatrix layout as
  9. an instance of <code class="code">class Datamatrix</code></p></li><li><p>Create an instance of a suitable backend for the chosen output format
  10. (image or postscript) by calling the
  11. <code class="code">DatamatrixBackenFactory::Create()</code></p></li><li><p>Encode data and send it back to the browser or to a file with a call
  12. to the backend <code class="code">Backend::Stroke()</code> method.</p></li></ol></div><p>
  13. </p><p>The following script shows how to create the simplest possible barcode (in PNG
  14. format) representing the data string "<code class="code">The first datamatrix</code>" encoded
  15. using all default values. The resulting barcode is shown in <a class="xref" href="ch25s02.html#fig.datamatrix_ex00" title="Figure 25.5. The simplest possible datamatrix script (datamatrix_ex00.php)">Figure 25.5</a></p><p>
  16. </p><div class="example"><a name="example.datamatrix_ex00"></a><p class="title"><b>Example 25.1. The simplest possible datamatrix script (<code class="filename">datamatrix_ex00.php</code>) </b></p><div class="example-contents"><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  17. 2
  18. 3
  19. 4
  20. 5
  21. 6
  22. 7
  23. 8
  24. 9
  25. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content=&quot;text/plain; charset=utf-8&quot;</span><span class="hl-comment"></span><span class="hl-code">
  26. </span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/datamatrix/datamatrix.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
  27. </span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">The first datamatrix</span><span class="hl-quotes">'</span><span class="hl-code">;
  28. </span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  29. </span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-brackets">)</span><span class="hl-code">;
  30. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  31. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.datamatrix_ex00"></a><p class="title"><b>Figure 25.5. The simplest possible datamatrix script <code class="uri"><a class="uri" href="example_src/datamatrix_ex00.html" target="_top">(<code class="filename">datamatrix_ex00.php</code>)</a></code> </b></p><div class="figure-contents"><span class="inlinemediaobject"><img src="images/datamatrix_ex00.png" alt="The simplest possible datamatrix script (datamatrix_ex00.php)"></span></div></div><p><br class="figure-break">
  32. </p><p>(As can be seen this follows the same principles as the creation of PDF417
  33. symbols)</p><p>The principle is the same for all type of data matrix symbol creations. We first
  34. create an instance of the chosen encoder. In this case a standard ECC-200 encoder by
  35. creating an instance of <code class="code">class Datamatrix</code>. We then create a suitable
  36. backend that handles the output of the barcode. By default the output will be an
  37. image encoded in the PNG image format.</p><p>The final step is to send back the generated image to the browser with a call to
  38. the method <code class="code">Backend::Stroke()</code> with the data to be encoded as its first
  39. argument.</p><p>The example above does not have any error handling. If there is some error in the
  40. process an exception will be thrown in the same way as in other places in the
  41. library. The default exception will display a standard library image error box. An
  42. example of this is shown in <a class="xref" href="ch25s02.html#fig.datamatrix-error-image" title="Figure 25.6. Datamatrix error image">Figure 25.6</a>. </p><div class="figure"><a name="fig.datamatrix-error-image"></a><p class="title"><b>Figure 25.6. Datamatrix error image</b></p><div class="figure-contents"><div class="mediaobject"><img src="images/datamatrix_errormsg.png" alt="Datamatrix error image"></div></div></div><br class="figure-break"><p>If some additional processing is necessary and just display a text based
  43. re-formatted error message we could change the above code to catch this exception as
  44. the following example shows.</p><p>
  45. </p><div class="example"><a name="example.datamatrix_ex0"></a><p class="title"><b>Example 25.2. Datamatrix with basic error handling (<code class="filename">datamatrix_ex0.php</code>) </b></p><div class="example-contents"><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  46. 2
  47. 3
  48. 4
  49. 5
  50. 6
  51. 7
  52. 8
  53. 9
  54. 10
  55. 11
  56. 12
  57. 13
  58. 14
  59. 15
  60. 16
  61. 17
  62. 18
  63. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content=&quot;text/plain; charset=utf-8&quot;</span><span class="hl-comment"></span><span class="hl-code">
  64. </span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/datamatrix/datamatrix.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
  65. </span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">The first datamatrix</span><span class="hl-quotes">'</span><span class="hl-code">;
  66. </span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  67. </span><span class="hl-var">$encoder</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetEncoding</span><span class="hl-brackets">(</span><span class="hl-identifier">ENCODING_ASCII</span><span class="hl-brackets">)</span><span class="hl-code">;
  68. </span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-brackets">)</span><span class="hl-code">;
  69. </span><span class="hl-comment">//</span><span class="hl-comment"> We increase the module width to 3 pixels</span><span class="hl-comment"></span><span class="hl-code">
  70. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">;
  71. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  72. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  73. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  74. </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">Datamatrix error: </span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-quotes">&quot;</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
  75. </span><span class="hl-reserved">exit</span><span class="hl-brackets">(</span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code">;
  76. </span><span class="hl-brackets">}</span><span class="hl-code">
  77. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.datamatrix_ex0"></a><p class="title"><b>Figure 25.7. Datamatrix with basic error handling <code class="uri"><a class="uri" href="example_src/datamatrix_ex0.html" target="_top">(<code class="filename">datamatrix_ex0.php</code>)</a></code> </b></p><div class="figure-contents"><span class="inlinemediaobject"><img src="images/datamatrix_ex0.png" alt="Datamatrix with basic error handling (datamatrix_ex0.php)"></span></div></div><p><br class="figure-break">
  78. </p><p>In contrast to the PDF417 encodation process there is no option to select an level
  79. of error correction. The error correction level is automatically specified in the
  80. standard depending on the size of the barcode. As a final initial example the next
  81. script uses the backend method <code class="code">Backend::SetModuleWidth($aWidth)</code> to
  82. increase the width of one module.</p><p>
  83. </p><div class="example"><a name="example.datamatrix_ex1"></a><p class="title"><b>Example 25.3. Datamatrix with modified module width (<code class="filename">datamatrix_ex1.php</code>) </b></p><div class="example-contents"><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  84. 2
  85. 3
  86. 4
  87. 5
  88. 6
  89. 7
  90. 8
  91. 9
  92. 10
  93. 11
  94. 12
  95. 13
  96. 14
  97. 15
  98. 16
  99. 17
  100. 18
  101. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content=&quot;text/plain; charset=utf-8&quot;</span><span class="hl-comment"></span><span class="hl-code">
  102. </span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/datamatrix/datamatrix.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
  103. </span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">123456</span><span class="hl-quotes">'</span><span class="hl-code">;
  104. </span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  105. </span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-brackets">)</span><span class="hl-code">;
  106. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">;
  107. </span><span class="hl-comment">//</span><span class="hl-comment"> Create the barcode from the given data string and write to output file</span><span class="hl-comment"></span><span class="hl-code">
  108. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  109. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  110. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  111. </span><span class="hl-var">$errstr</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  112. </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Datamatrix error message: </span><span class="hl-var">$errstr</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
  113. </span><span class="hl-brackets">}</span><span class="hl-code">
  114. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.datamatrix_ex1"></a><p class="title"><b>Figure 25.8. Datamatrix with modified module width <code class="uri"><a class="uri" href="example_src/datamatrix_ex1.html" target="_top">(<code class="filename">datamatrix_ex1.php</code>)</a></code> </b></p><div class="figure-contents"><span class="inlinemediaobject"><img src="images/datamatrix_ex1.png" alt="Datamatrix with modified module width (datamatrix_ex1.php)"></span></div></div><p><br class="figure-break">
  115. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2614675"></a>25.2.2. Error handling</h3></div></div></div><p>As in other parts of the library the Datamatrix module throws an exception when an
  116. error occurs. As shown in the previous section an error image is the default if no
  117. explicit <code class="code">try {} catch {}</code> statement is added to the script.</p><p>The script below shows how to catch the error, do some possible clean up and then
  118. explicitly create and send back the error image.</p><p>
  119. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  120. 2
  121. 3
  122. 4
  123. 5
  124. 6
  125. 7
  126. 8
  127. 9
  128. 10
  129. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
  130. ...
  131. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  132. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  133. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  134. </span><span class="hl-identifier">doCleanup</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  135. </span><span class="hl-var">$errobj</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">DMErrObjectImg</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  136. </span><span class="hl-var">$errobj</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Raise</span><span class="hl-brackets">(</span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">getMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
  137. </span><span class="hl-brackets">}</span><span class="hl-code">
  138. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
  139. </p><p>another variant of this would be to re-throw the exception after the cleanup has
  140. been performed as the following example shows</p><p>
  141. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  142. 2
  143. 3
  144. 4
  145. 5
  146. 6
  147. 7
  148. 8
  149. 9
  150. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
  151. ...
  152. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  153. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  154. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  155. </span><span class="hl-identifier">doCleanup</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  156. </span><span class="hl-reserved">throw</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-code">;
  157. </span><span class="hl-brackets">}</span><span class="hl-code">
  158. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
  159. </p><p>It is also possible to get hold of the internal error code that corresponds to
  160. each error message by calling the PHP standard exception method
  161. <code class="code">Exception::getCode()</code> as the following example shows</p><p>
  162. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  163. 2
  164. 3
  165. 4
  166. 5
  167. 6
  168. 7
  169. 8
  170. 9
  171. 10
  172. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
  173. ...
  174. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  175. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  176. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  177. </span><span class="hl-var">$errstr</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  178. </span><span class="hl-var">$errcode</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetCode</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  179. </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Datamatrix error (</span><span class="hl-var">$errcode</span><span class="hl-string">). Message: </span><span class="hl-var">$errstr</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
  180. </span><span class="hl-brackets">}</span><span class="hl-code">
  181. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
  182. </p><p><a class="xref" href="ch25s02.html#table.datamatrix-error-messages" title="Table 25.3. Datamatrix error messages">Table 25.3</a> lists the errors that can be
  183. thrown by the datamatrix module (the table deliberately excludes internal error
  184. messages).</p><p>
  185. </p><div class="table"><a name="table.datamatrix-error-messages"></a><p class="title"><b>Table 25.3. Datamatrix error messages</b></p><div class="table-contents"><table summary="Datamatrix error messages" border="1"><colgroup><col><col></colgroup><thead><tr><th align="center">Error number</th><th align="center">Error messages</th></tr></thead><tbody><tr><td class="error-number" align="center">-1</td><td class="error-text">Data is too long to fit specified symbol
  186. size</td></tr><tr><td class="error-number" align="center">-2</td><td class="error-text">The BASE256 data is too long to fit
  187. available symbol size</td></tr><tr><td class="error-number" align="center">-3</td><td class="error-text">Data must have at least three characters
  188. for C40 encodation</td></tr><tr><td class="error-number" align="center">-4</td><td class="error-text">Data must have at least three characters
  189. for TEXT encodation</td></tr><tr><td class="error-number" align="center">-8</td><td class="error-text">The given data can not be encoded using X12
  190. encodation.</td></tr><tr><td class="error-number" align="center">-9</td><td class="error-text">The "tilde" encoded data is not
  191. valid.</td></tr><tr><td class="error-number" align="center">-10</td><td class="error-text">Data must have at least three characters
  192. for X12 encodation</td></tr><tr><td class="error-number" align="center">-11</td><td class="error-text">Specified data can not be encoded with
  193. datamatrix 000 140</td></tr><tr><td class="error-number" align="center">-12</td><td class="error-text">Can not create image</td></tr><tr><td class="error-number" align="center">-13</td><td class="error-text">Invalid color specification</td></tr><tr><td class="error-number" align="center">-15</td><td class="error-text">This PHP installation does not support the
  194. chosen image encoding format</td></tr><tr><td class="error-number" align="center">-20</td><td class="error-text">The specification for shape of matrix is
  195. out of bounds (0,29)</td></tr><tr><td class="error-number" align="center">-21</td><td class="error-text">Cannot open the data file specifying bit
  196. placement for Datamatrix 200</td></tr><tr><td class="error-number" align="center">-22</td><td class="error-text">Datafile for bit placement is corrupt, crc
  197. checks fails.</td></tr><tr><td class="error-number" align="center">-26</td><td class="error-text">Cannot open the data file specifying bit
  198. placement for Datamatrix 140</td></tr><tr><td class="error-number" align="center">-30</td><td class="error-text">The symbol size specified for ECC140 type
  199. Datamatrix is not valid</td></tr><tr><td class="error-number" align="center">-31</td><td class="error-text">Data is too long to fit into any available
  200. matrix size for datamatrix 140</td></tr><tr><td class="error-number" align="center">-34</td><td class="error-text">Cannot open file %s for writing.</td></tr><tr><td class="error-number" align="center">-35</td><td class="error-text">Cannot write to file %s .</td></tr><tr><td class="error-number" align="center">-99</td><td class="error-text">EDIFACT encodation not implemented</td></tr><tr><td class="error-number" align="center">-100</td><td class="error-text">
  201. <p>Datamatrix Error: HTTP headers have already been
  202. sent.</p>
  203. <p>Caused by output from file %s at line %d</p>
  204. <p>Explanation: HTTP headers have already been sent back to
  205. the browser indicating the data as text before the library
  206. got a chance to send it's image HTTP header to this browser.
  207. This makes it impossible for the Datamatrix library to send
  208. back image data to the browser (since that would be
  209. interpretated as text by the browser and show up as junk
  210. text).</p>
  211. <p>Most likely you have some text in your script before the
  212. call to DatamatrixBackend::Stroke(). </p>
  213. <p>If this texts gets sent back to the browser the browser
  214. will assume that all data is plain text. Look for any text
  215. (even spaces and newlines) that might have been sent back to
  216. the browser.</p>
  217. <p>For example it is a common mistake to leave a blank line
  218. before the opening "&lt;?php"</p>
  219. </td></tr></tbody></table></div></div><p><br class="table-break">
  220. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2615310"></a>25.2.3. Encodation options</h3></div></div></div><p>The primary encodation option is to manually specify the shape of the Datamatrix
  221. barcode. By default the symbol size will be chosen as the smallest possible. However
  222. some application require that usage of a fixed size symbol shape. </p><p>The available shapes are listed in <a class="xref" href="ch25.html#table.datamatrix-ecc200-size" title="Table 25.2. Maximum data capacity for the different symbol sizes in ECC-200 Data Matrix subset.">Table 25.2</a>. The wanted shape is specified when
  223. the instance of the encoder is created or by a call to
  224. <code class="code">Datamatrix::SetSize()</code>. The shape is specified by a symbolic
  225. constant that corresponds to each available shape in <a class="xref" href="ch25.html#table.datamatrix-ecc200-size" title="Table 25.2. Maximum data capacity for the different symbol sizes in ECC-200 Data Matrix subset.">Table 25.2</a>. The symbol name is
  226. "<code class="code">DMAT_&lt;H&gt;x&lt;W&gt;</code>" where <code class="code">&lt;H&gt;</code> is the height (in
  227. modules) and <code class="code">&lt;W&gt;</code> is the width (in modules). For example the
  228. following line specifies a 24 module square symbol </p><p>
  229. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  230. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder-&gt;SetSize(DMAT_24x24);</span></pre></td></tr></table></div><p>
  231. </p><p>In addition to the sizes specified in <a class="xref" href="ch25.html#table.datamatrix-ecc200-size" title="Table 25.2. Maximum data capacity for the different symbol sizes in ECC-200 Data Matrix subset.">Table 25.2</a> there is also an option to specify
  232. automatic sizing (which is the default). The following script sets the sizing to be
  233. automatic.</p><p>
  234. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  235. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder-&gt;SetSize(DMAT_AUTO);</span></pre></td></tr></table></div><p>
  236. </p><p>As was discussed in <a class="xref" href="ch25.html#sec.encodation-efficiency" title="25.1.5.  Encodation efficiency">Section 25.1.5</a> there are
  237. several ways by which data can be encoded. By default the encoder will use an
  238. optimal algorithm to create a combination of the available encodation schema to
  239. create the smallest possible symbol. In some application it might however be stated
  240. that a specific encodation method should be chosen. </p><p>The encoding method is a property of the encodation class and is set with a call
  241. to </p><p>
  242. </p><div class="itemizedlist"><ul type="disc"><li><p><code class="code">Datamatrix::SetEncoding($aEncoding=ENCODING_ASCII)</code>
  243. </p></li></ul></div><p>
  244. </p><p>The encoding is specified as one of the symbolic constants shown in <a class="xref" href="ch25s02.html#table.datamatrix-symbikc-encoding" title="Table 25.4. Datamatrix encodation schemas">Table 25.4</a></p><div class="table"><a name="table.datamatrix-symbikc-encoding"></a><p class="title"><b>Table 25.4. Datamatrix encodation schemas</b></p><div class="table-contents"><table summary="Datamatrix encodation schemas" border="1"><colgroup><col><col><col></colgroup><thead><tr><th>Symbolic constant</th><th>Encoding schema</th><th>Character set</th></tr></thead><tbody><tr><td>ENCODING_AUTO</td><td>--</td><td>An optimal combination of all encodation schema</td></tr><tr><td>ENCODING_ASCII</td><td>ASCII</td><td>Most efficient for numeric data</td></tr><tr><td>ENCODING_C40</td><td>C40</td><td>Primarily upper-case alphanumeric</td></tr><tr><td>ENCODING_TEXT</td><td>Text</td><td>Primarily lower-case alphanumeric</td></tr><tr><td>ENCODING_X12</td><td>X12</td><td>ANSI X12 EDI data set</td></tr><tr><td>ENCODING_EDIFACT</td><td>EDIFACT</td><td>ASCII values 32-94</td></tr><tr><td>ENCODING_BASE256</td><td>Base 256</td><td>All byte values 0-255</td></tr></tbody></table></div></div><br class="table-break"><p>The following example sets the ASCII encodation schema</p><p>
  245. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  246. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder-&gt;SetEncoding(ENCODING_ASCII);</span></pre></td></tr></table></div><p>
  247. </p><p>The default automatic encoding is the same as</p><p>
  248. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  249. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$encoder-&gt;SetSize(ENCODING_AUTO);</span></pre></td></tr></table></div><p>
  250. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2615653"></a>25.2.4. Processing special input characters</h3></div></div></div><p>In order to allow the specification of special input data in normal ASCII
  251. encodation for easy entering from a keyboard the library supports what is commonly
  252. known as "tilde" processing. When this is enabled (it is disabled by default)
  253. certain character sequences that begins with a tilde sign (i.e. "~") will be
  254. translated to a special ASCII value that cannot normally be entered from a
  255. keyboard.</p><p>When tilde mode is enabled with a call to the method </p><p>
  256. </p><div class="itemizedlist"><ul type="disc"><li><p><code class="code">Datamatrix::SetTilde($aFlg=true)</code></p></li></ul></div><p>
  257. </p><p><a class="xref" href="ch25s02.html#table.datamatrix-tilde-processing" title="Table 25.5. Tilde processing translating">Table 25.5</a> lists the translations
  258. that will then be enabled on the input data. Some of the translations are technical
  259. and requires full understanding of Datamatrix standard to be used.</p><div class="table"><a name="table.datamatrix-tilde-processing"></a><p class="title"><b>Table 25.5. Tilde processing translating</b></p><div class="table-contents"><table summary="Tilde processing translating" border="1"><colgroup><col><col></colgroup><thead><tr><th>Input sequence</th><th>Translation</th></tr></thead><tbody><tr><td>~X : where 'X' is a character in the range [@-Z]</td><td>Translates to ASCII value 0-25, i.e. ~@==0, ~A==1, ~B==2 ,
  260. ...</td></tr><tr><td>~1</td><td>Represents the character FNC1. Alternate Data Type Identifier.
  261. See Table 6: ISO 16022</td></tr><tr><td>~2nnmmfffggg</td><td>
  262. <p>Structured Append. This code is only allowed in the first
  263. position of the data. Up to 16 ECC 200 symbols may be appended
  264. in a structured format. The structured append is specified with
  265. symbol index, total number of symbols and a file identification. </p>
  266. <p>The first two values "nn" is the position of this particular
  267. symbol specified as two digits in the range of 01-16. </p>
  268. <p>The second two values "mm" is the total number of symbols in
  269. this structured append in the range 02-16 specified as two
  270. digits. </p>
  271. <p>The last two 3 digit codewords are the file identification
  272. specified with digits and necessary leading 0:s to make it a
  273. full three digits. For example. Assume that we want to encode
  274. the 4:th symbol from a total of 9 symbols and with the file
  275. identification "0,1". This would then be encoded as
  276. "~20409000001". Note: Internally this is translated to three
  277. codewords with the reserved starting codeword of ASCII
  278. 233.</p>
  279. </td></tr><tr><td>~5 and ~6</td><td>
  280. <p>The special 05 and 06 Macros. Can only be in the first
  281. position and is used to encode industry standard headers in
  282. certain structured formats. </p>
  283. <p>Macro 05 is translated by the barcode reader to : Symbol
  284. prefix: chr(30) chr(05) chr(29) Symbol postfix: chr(30) chr(04)
  285. Macro 06 is translated by the barcode reader to : Symbol prefix:
  286. chr(30) chr(06) chr(29 Symbol postfix: chr(30) chr(04)</p>
  287. </td></tr><tr><td>~7nnnnnn</td><td>
  288. <p>Extended Channel Interpretation (ECI) nnnnnn. </p>
  289. <p>The ECI protocol allows the output data stream to have
  290. interpretations different from that of the default character
  291. set. See "<span class="italic">Extended Channel
  292. Interpretation Assignments</span>" document (available
  293. from ISO) for a list of channels and there meaning. </p>
  294. <p>The ECI is identified by a 6-digit number which is encoded
  295. according to Table 10: in the ISO 16022:2000 specification. This
  296. is the encodation that is used for the "~7" tilde specification
  297. of the ECI protocol.</p>
  298. </td></tr><tr><td>~9</td><td>
  299. <p>Send the special control code (ASCII=234) so that the reader
  300. will interpret the rest of the symbol as a bar code reader
  301. programming instruction.</p>
  302. </td></tr><tr><td>~dnnn</td><td>
  303. <p>Character value as 3 digits, i.e. ~d142 means ASCII value
  304. 142</p>
  305. </td></tr></tbody></table></div></div><br class="table-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2615957"></a>25.2.5. Creating different backends</h3></div></div></div><p>In order to create the actual output one or more backends must be created. The
  306. Datamatrix supports the following backends:</p><p>
  307. </p><div class="itemizedlist"><ul type="disc"><li><p><code class="code">BACKEND_IMAGE</code>, Create an image backend. This is the
  308. default backend if no explicit backend is specified.</p></li><li><p><code class="code">BACKEND_PS</code>, Create a postscript backend. The text string
  309. that represents the postscript for the barcode is returned directly from
  310. the <code class="code">Backend::Stroke()</code></p></li><li><p><code class="code">BACKEND_EPS</code>, Create an encapsulated postscript
  311. backend</p></li><li><p><code class="code">BACKEND_ASCII</code>, This is a special backend which will
  312. generate an ASCII rendering of the datamatrix barcode. This is mostly
  313. practical for technical investigations regarding the technical structure
  314. of a Datamatrix barcode.</p></li></ul></div><p>
  315. </p><p>The following code snippet shows two ways of creating a barcode image
  316. backend.</p><p>
  317. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  318. 2
  319. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Create an image backend
  320. $backend = DatamatrixBackendFactory::Create($encoder);</span></pre></td></tr></table></div><p>
  321. </p><p>
  322. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  323. 2
  324. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Create an image backend
  325. $backend = DatamatrixBackendFactory::Create($encoder, BACKEND_IMAGE);</span></pre></td></tr></table></div><p>
  326. </p><p>The following code shows a complete script to generate a postscript output</p><p>
  327. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  328. 2
  329. 3
  330. 4
  331. 5
  332. 6
  333. 7
  334. 8
  335. 9
  336. 10
  337. 11
  338. 12
  339. 13
  340. 14
  341. 15
  342. 16
  343. 17
  344. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
  345. </span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/datamatrix/datamatrix.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
  346. </span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">0123456789</span><span class="hl-quotes">'</span><span class="hl-code">;
  347. </span><span class="hl-comment">//</span><span class="hl-comment"> Create and set parameters for the encoder</span><span class="hl-comment"></span><span class="hl-code">
  348. </span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  349. </span><span class="hl-comment">//</span><span class="hl-comment"> Create the image backend (default)</span><span class="hl-comment"></span><span class="hl-code">
  350. </span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_PS</span><span class="hl-brackets">)</span><span class="hl-code">;
  351. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  352. </span><span class="hl-var">$ps_txt</span><span class="hl-code"> = </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
  353. </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;pre&gt;</span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$ps_txt</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string">&lt;/pre&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;
  354. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  355. </span><span class="hl-var">$errstr</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  356. </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Datamatrix error message: </span><span class="hl-var">$errstr</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
  357. </span><span class="hl-brackets">}</span><span class="hl-code">
  358. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
  359. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2616079"></a>25.2.6. Generic backend methods</h3></div></div></div><p>The following methods are available to adjust the final look and feel of the
  360. barcode</p><p>
  361. </p><div class="orderedlist"><ol type="1"><li><p><code class="code">Backend::SetColor($aOne, $aZero,
  362. $aBackground='white')</code></p><p>the color of the 'black' and 'white' modules in the barcode and the
  363. quiet area around the barcode</p></li><li><p><code class="code">Backend::SetQuietZone($aSize)</code></p><p>the size of the "quiet zone" in pixels for the image backend and in
  364. points (1 pt = 1/72 inch) for the postscript backend</p></li><li><p><code class="code">Backend::SetModuleWidth($aWidth)</code></p><p>the module width specified in pixels for the image backend and in
  365. points (1 pt = 1/72 inch) for the postscript backend</p></li><li><p><code class="code">Backend::Stroke($aData, $aFileName='')</code></p><p>create the barcode and send it back the client or store it to a file
  366. if the second parameter is set. For postscript backends the postscript
  367. string is returned directly from the method. (See example above)</p></li></ol></div><p>
  368. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2616167"></a>25.2.7. Image backend methods</h3></div></div></div><p>For the image backend it is possible to adjust the image encoding format with the
  369. following method</p><p>
  370. </p><div class="orderedlist"><ol type="1"><li><p><code class="code">Backend::SetImgFormat($aFormat,$aQuality=75)</code></p><p>Specify image format. Possible values are </p><p>
  371. </p><div class="itemizedlist"><ul type="disc"><li><p><code class="code">'auto'</code></p></li><li><p><code class="code">'png'</code></p></li><li><p><code class="code">'jpeg'</code></p></li><li><p><code class="code">'gif'</code></p></li></ul></div><p>
  372. </p><p>For 'jpeg' format the quality parameter is a number in range [1-100]
  373. and specified how much compression / (Data loss) should be used. 100=no
  374. compression. Normal values are in the range [60-95]</p><p>The following example sets the image format to 'JPEG' with quality
  375. 80.</p><p>
  376. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  377. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$backend-&gt;SetImgFormat('jpeg', 80);</span></pre></td></tr></table></div><p>
  378. </p></li></ol></div><p>
  379. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2616274"></a>25.2.8. Postscript backend format options</h3></div></div></div><p>For postscript backend it is possible to select whether the postscript should be
  380. generated as encapsulated postscript. This is controlled by the method</p><p>
  381. </p><div class="itemizedlist"><ul type="disc"><li><p><code class="code">Backend::SetEPS($aFlg=true)</code></p></li></ul></div><p>
  382. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2616306"></a>25.2.9. A template to create barcodes</h3></div></div></div><p>In the example directory in the distribution
  383. ('<code class="filename">datamatrix/examples</code>') you can find many more examples on
  384. how to create barcodes. As a good start the following (simple) template may be used
  385. as a base for further customizations.</p><p>
  386. </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
  387. 2
  388. 3
  389. 4
  390. 5
  391. 6
  392. 7
  393. 8
  394. 9
  395. 10
  396. 11
  397. 12
  398. 13
  399. 14
  400. 15
  401. 16
  402. 17
  403. 18
  404. 19
  405. 20
  406. 21
  407. 22
  408. 23
  409. 24
  410. 25
  411. 26
  412. 27
  413. 28
  414. 29
  415. 30
  416. 31
  417. 32
  418. 33
  419. 34
  420. 35
  421. 36
  422. 37
  423. 38
  424. </pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
  425. </span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/datamatrix/datamatrix.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
  426. </span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">0123456789</span><span class="hl-quotes">'</span><span class="hl-code">;
  427. </span><span class="hl-var">$shape</span><span class="hl-code"> = </span><span class="hl-identifier">DMAT_AUTO</span><span class="hl-code">;
  428. </span><span class="hl-var">$encoding</span><span class="hl-code"> = </span><span class="hl-identifier">ENCODING_AUTO</span><span class="hl-code">;
  429. </span><span class="hl-var">$modulewidth</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">;
  430. </span><span class="hl-var">$quietzone</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
  431. </span><span class="hl-var">$color1</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">black</span><span class="hl-quotes">'</span><span class="hl-code">;
  432. </span><span class="hl-var">$color0</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-code">;
  433. </span><span class="hl-var">$colorq</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-code">;
  434. </span><span class="hl-var">$outputfile</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-quotes">'</span><span class="hl-code">;
  435. </span><span class="hl-comment">//</span><span class="hl-comment"> Create and set parameters for the encoder</span><span class="hl-comment"></span><span class="hl-code">
  436. </span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$shape</span><span class="hl-brackets">)</span><span class="hl-code">;
  437. </span><span class="hl-var">$encoder</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetEncoding</span><span class="hl-brackets">(</span><span class="hl-var">$encoding</span><span class="hl-brackets">)</span><span class="hl-code">;
  438. </span><span class="hl-comment">//</span><span class="hl-comment"> Create the image backend (default)</span><span class="hl-comment"></span><span class="hl-code">
  439. </span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">DatamatrixBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-brackets">)</span><span class="hl-code">;
  440. </span><span class="hl-comment">//</span><span class="hl-comment"> By default the module width is 2 pixel so we increase it a bit</span><span class="hl-comment"></span><span class="hl-code">
  441. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-var">$modulewidth</span><span class="hl-brackets">)</span><span class="hl-code">;
  442. </span><span class="hl-comment">//</span><span class="hl-comment"> Set Quiet zone</span><span class="hl-comment"></span><span class="hl-code">
  443. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetQuietZone</span><span class="hl-brackets">(</span><span class="hl-var">$quietzone</span><span class="hl-brackets">)</span><span class="hl-code">;
  444. </span><span class="hl-comment">//</span><span class="hl-comment"> Set other than default colors (one, zero, quiet zone/background)</span><span class="hl-comment"></span><span class="hl-code">
  445. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetColor</span><span class="hl-brackets">(</span><span class="hl-var">$color1</span><span class="hl-code">, </span><span class="hl-var">$color0</span><span class="hl-code">, </span><span class="hl-var">$colorq</span><span class="hl-brackets">)</span><span class="hl-code">;
  446. </span><span class="hl-comment">//</span><span class="hl-comment"> Create the barcode from the given data string and write to output file</span><span class="hl-comment"></span><span class="hl-code">
  447. </span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  448. </span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-code">,</span><span class="hl-var">$outputfile</span><span class="hl-brackets">)</span><span class="hl-code">;
  449. </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
  450. </span><span class="hl-var">$errstr</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
  451. </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Datamatrix error message: </span><span class="hl-var">$errstr</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
  452. </span><span class="hl-brackets">}</span><span class="hl-code">
  453. </span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
  454. </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2616350"></a>25.2.10. Sample application</h3></div></div></div><p>As an example the library includes a WEB-based demo barcode creation application.
  455. This application can be used to easily create barcode through it's WEB interface. It
  456. is available at '<code class="filename">datamatrix/demoapp/index.html</code>'</p><p>This application is primarily included as a demo on the features available in the
  457. library and not as a finalized product.</p><p><a class="xref" href="ch25s02.html#fig.datamatrix-demoapp" title="Figure 25.9. Datamatrix WEB-based demo application">Figure 25.9</a> shows a screen shot of the
  458. application interface.</p><div class="figure"><a name="fig.datamatrix-demoapp"></a><p class="title"><b>Figure 25.9. Datamatrix WEB-based demo application</b></p><div class="figure-contents"><div class="mediaobject"><img src="images/datamatrix-demoapp.png" alt="Datamatrix WEB-based demo application"></div></div></div><br class="figure-break"></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch25.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch25.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch25s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 25. Datamatrix (2D-Barcode) </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 25.3. Example script</td></tr></table></div></body></html>