This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/includes/jpgraph/docs/chunkhtml/ch26s02.html

642 lines
61 KiB
HTML
Raw Normal View History

2011-05-28 09:51:52 +00:00
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Creating barcodes</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch26.html" title="Chapter 26. Datamatrix (2D-Barcode)"></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">Creating barcodes</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 26. Datamatrix (2D-Barcode)</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Creating barcodes"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2603445"></a>Creating barcodes</h2></div></div></div>
<p>In order to use datamatrix barcodes the module
"<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
barcodes with concepts of an encoder and backend. The principle of the overall
encodation process is shown in <a class="xref" href="ch26s02.html#fig.datamatrix-encodation-principle" title="Figure 26.4. Datamatrix encodation principle">Figure 26.4. Datamatrix encodation principle</a></p>
<div class="figure"><a name="fig.datamatrix-encodation-principle"></a><p class="title"><b>Figure 26.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" title="Getting started"><div class="titlepage"><div><div><h3 class="title"><a name="id2605827"></a>Getting started</h3></div></div></div>
<p>Assuming that the library is installed where it can be found by PHP it is now very
simple to create a basic Data Matrix symbol using just default values. We first show
the complete first example and then discuss it. In the following scripts we will
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>
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p>Create an instance of the encoder with the chosen datamatrix layout as
an instance of <code class="code">class Datamatrix</code></p>
</li><li class="listitem">
<p>Create an instance of a suitable backend for the chosen output format
(image or postscript) by calling the
<code class="code">DatamatrixBackenFactory::Create()</code></p>
</li><li class="listitem">
<p>Encode data and send it back to the browser or to a file with a call
to the backend <code class="code">Backend::Stroke()</code> method.</p>
</li></ol></div><p>
</p>
<p>The following script shows how to create the simplest possible barcode (in PNG
format) representing the data string "<code class="code">The first datamatrix</code>" encoded
using all default values. The resulting barcode is shown in <a class="xref" href="ch26s02.html#fig.datamatrix_ex00" title="Figure 26.5. The simplest possible datamatrix script (datamatrix_ex00.php)">Figure 26.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> </a></p>
<p>
</p><div class="example"><a name="example.datamatrix_ex00"></a><p class="title"><b>Example 26.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
2
3
4
5
6
7
8
9
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</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">;
</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">;
</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">;
</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">;
</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">;
</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 26.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">
</p>
<p>(As can be seen this follows the same principles as the creation of PDF417
symbols)</p>
<p>The principle is the same for all type of data matrix symbol creations. We first
create an instance of the chosen encoder. In this case a standard ECC-200 encoder by
creating an instance of <code class="code">class Datamatrix</code>. We then create a suitable
backend that handles the output of the barcode. By default the output will be an
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
the method <code class="code">Backend::Stroke()</code> with the data to be encoded as its first
argument.</p>
<p>The example above does not have any error handling. If there is some error in the
process an exception will be thrown in the same way as in other places in the
library. The default exception will display a standard library image error box. An
example of this is shown in <a class="xref" href="ch26s02.html#fig.datamatrix-error-image" title="Figure 26.6. Datamatrix error image">Figure 26.6. Datamatrix error image</a>. </p>
<div class="figure"><a name="fig.datamatrix-error-image"></a><p class="title"><b>Figure 26.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
re-formatted error message we could change the above code to catch this exception as
the following example shows.</p>
<p>
</p><div class="example"><a name="example.datamatrix_ex0"></a><p class="title"><b>Example 26.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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</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">;
</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">;
</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">;
</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">;
</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">;
</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">
</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">;
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</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">;
</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">
</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">;
</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">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</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 26.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">
</p>
<p>In contrast to the PDF417 encodation process there is no option to select an level
of error correction. The error correction level is automatically specified in the
standard depending on the size of the barcode. As a final initial example the next
script uses the backend method <code class="code">Backend::SetModuleWidth($aWidth)</code> to
increase the width of one module.</p>
<p>
</p><div class="example"><a name="example.datamatrix_ex1"></a><p class="title"><b>Example 26.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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</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">;
</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">;
</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">;
</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">;
</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">;
</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">
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</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">;
</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">
</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">;
</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">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</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 26.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">
</p>
</div>
<div class="sect2" title="Error handling"><div class="titlepage"><div><div><h3 class="title"><a name="id2606128"></a>Error handling</h3></div></div></div>
<p>As in other parts of the library the Datamatrix module throws an exception when an
error occurs. As shown in the previous section an error image is the default if no
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
explicitly create and send back the error image.</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
...
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</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">;
</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">
</span><span class="hl-identifier">doCleanup</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</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">;
</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">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
</p>
<p>another variant of this would be to re-throw the exception after the cleanup has
been performed as the following example shows</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
...
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</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">;
</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">
</span><span class="hl-identifier">doCleanup</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">throw</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-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
</p>
<p>It is also possible to get hold of the internal error code that corresponds to
each error message by calling the PHP standard exception method
<code class="code">Exception::getCode()</code> as the following example shows</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
...
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</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">;
</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">
</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">;
</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">;
</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">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
</p>
<p><a class="xref" href="ch26s02.html#table.datamatrix-error-messages" title="Table 26.3. Datamatrix error messages">Table 26.3. Datamatrix error messages</a> lists the errors that can be
thrown by the datamatrix module (the table deliberately excludes internal error
messages).</p>
<p>
</p><div class="table"><a name="table.datamatrix-error-messages"></a><p class="title"><b>Table 26.3. Datamatrix error messages</b></p><div class="table-contents">
<table summary="Datamatrix error messages" border="1"><colgroup><col class="newCol1"><col class="c1"></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
size</td></tr><tr><td class="error-number" align="center">-2</td><td class="error-text">The BASE256 data is too long to fit
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
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
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
encodation.</td></tr><tr><td class="error-number" align="center">-9</td><td class="error-text">The "tilde" encoded data is not
valid.</td></tr><tr><td class="error-number" align="center">-10</td><td class="error-text">Data must have at least three characters
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
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
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
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
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
checks fails.</td></tr><tr><td class="error-number" align="center">-26</td><td class="error-text">Cannot open the data file specifying bit
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
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
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">
<p>Datamatrix Error: HTTP headers have already been
sent.</p>
<p>Caused by output from file %s at line %d</p>
<p>Explanation: HTTP headers have already been sent back to
the browser indicating the data as text before the library
got a chance to send it's image HTTP header to this browser.
This makes it impossible for the Datamatrix library to send
back image data to the browser (since that would be
interpretated as text by the browser and show up as junk
text).</p>
<p>Most likely you have some text in your script before the
call to DatamatrixBackend::Stroke(). </p>
<p>If this texts gets sent back to the browser the browser
will assume that all data is plain text. Look for any text
(even spaces and newlines) that might have been sent back to
the browser.</p>
<p>For example it is a common mistake to leave a blank line
before the opening "&lt;?php"</p>
</td></tr></tbody></table>
</div></div><p><br class="table-break">
</p>
</div>
<div class="sect2" title="Encodation options"><div class="titlepage"><div><div><h3 class="title"><a name="id2606133"></a>Encodation options</h3></div></div></div>
<p>The primary encodation option is to manually specify the shape of the Datamatrix
barcode. By default the symbol size will be chosen as the smallest possible. However
some application require that usage of a fixed size symbol shape. </p>
<p>The available shapes are listed in <a class="xref" href="ch26.html#table.datamatrix-ecc200-size" title="Table 26.2. Maximum data capacity for the different symbol sizes in ECC-200 Data Matrix subset.">Table 26.2. Maximum data capacity for the different symbol sizes in ECC-200 Data
Matrix subset.</a>. The wanted shape is specified when
the instance of the encoder is created or by a call to
<code class="code">Datamatrix::SetSize()</code>. The shape is specified by a symbolic
constant that corresponds to each available shape in <a class="xref" href="ch26.html#table.datamatrix-ecc200-size" title="Table 26.2. Maximum data capacity for the different symbol sizes in ECC-200 Data Matrix subset.">Table 26.2. Maximum data capacity for the different symbol sizes in ECC-200 Data
Matrix subset.</a>. The symbol name is
"<code class="code">DMAT_&lt;H&gt;x&lt;W&gt;</code>" where <code class="code">&lt;H&gt;</code> is the height (in
modules) and <code class="code">&lt;W&gt;</code> is the width (in modules). For example the
following line specifies a 24 module square symbol </p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</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>
</p>
<p>In addition to the sizes specified in <a class="xref" href="ch26.html#table.datamatrix-ecc200-size" title="Table 26.2. Maximum data capacity for the different symbol sizes in ECC-200 Data Matrix subset.">Table 26.2. Maximum data capacity for the different symbol sizes in ECC-200 Data
Matrix subset.</a> there is also an option to specify
automatic sizing (which is the default). The following script sets the sizing to be
automatic.</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</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>
</p>
<p>As was discussed in <a class="xref" href="ch26.html#sec.encodation-efficiency" title="Encodation efficiency"> Encodation efficiency</a> there are
several ways by which data can be encoded. By default the encoder will use an
optimal algorithm to create a combination of the available encodation schema to
create the smallest possible symbol. In some application it might however be stated
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
to </p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">Datamatrix::SetEncoding($aEncoding=ENCODING_ASCII)</code>
</p>
</li></ul></div><p>
</p>
<p>The encoding is specified as one of the symbolic constants shown in <a class="xref" href="ch26s02.html#table.datamatrix-symbikc-encoding" title="Table 26.4. Datamatrix encodation schemas">Table 26.4. Datamatrix encodation schemas</a></p>
<div class="table"><a name="table.datamatrix-symbikc-encoding"></a><p class="title"><b>Table 26.4. Datamatrix encodation schemas</b></p><div class="table-contents">
<table summary="Datamatrix encodation schemas" border="1"><colgroup><col class="c1"><col class="c2"><col class="newCol3"></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>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</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>
</p>
<p>The default automatic encoding is the same as</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</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>
</p>
</div>
<div class="sect2" title="Processing special input characters"><div class="titlepage"><div><div><h3 class="title"><a name="id2606704"></a>Processing special input characters</h3></div></div></div>
<p>In order to allow the specification of special input data in normal ASCII
encodation for easy entering from a keyboard the library supports what is commonly
known as "tilde" processing. When this is enabled (it is disabled by default)
certain character sequences that begins with a tilde sign (i.e. "~") will be
translated to a special ASCII value that cannot normally be entered from a
keyboard.</p>
<p>When tilde mode is enabled with a call to the method </p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">Datamatrix::SetTilde($aFlg=true)</code></p>
</li></ul></div><p>
</p>
<p><a class="xref" href="ch26s02.html#table.datamatrix-tilde-processing" title="Table 26.5. Tilde processing translating">Table 26.5. Tilde processing translating</a> lists the translations
that will then be enabled on the input data. Some of the translations are technical
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 26.5. Tilde processing translating</b></p><div class="table-contents">
<table summary="Tilde processing translating" border="1"><colgroup><col class="c1"><col class="c2"></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 ,
...</td></tr><tr><td>~1</td><td>Represents the character FNC1. Alternate Data Type Identifier.
See Table 6: ISO 16022</td></tr><tr><td>~2nnmmfffggg</td><td>
<p>Structured Append. This code is only allowed in the first
position of the data. Up to 16 ECC 200 symbols may be appended
in a structured format. The structured append is specified with
symbol index, total number of symbols and a file identification. </p>
<p>The first two values "nn" is the position of this particular
symbol specified as two digits in the range of 01-16. </p>
<p>The second two values "mm" is the total number of symbols in
this structured append in the range 02-16 specified as two
digits. </p>
<p>The last two 3 digit codewords are the file identification
specified with digits and necessary leading 0:s to make it a
full three digits. For example. Assume that we want to encode
the 4:th symbol from a total of 9 symbols and with the file
identification "0,1". This would then be encoded as
"~20409000001". Note: Internally this is translated to three
codewords with the reserved starting codeword of ASCII
233.</p>
</td></tr><tr><td>~5 and ~6</td><td>
<p>The special 05 and 06 Macros. Can only be in the first
position and is used to encode industry standard headers in
certain structured formats. </p>
<p>Macro 05 is translated by the barcode reader to : Symbol
prefix: chr(30) chr(05) chr(29) Symbol postfix: chr(30) chr(04)
Macro 06 is translated by the barcode reader to : Symbol prefix:
chr(30) chr(06) chr(29 Symbol postfix: chr(30) chr(04)</p>
</td></tr><tr><td>~7nnnnnn</td><td>
<p>Extended Channel Interpretation (ECI) nnnnnn. </p>
<p>The ECI protocol allows the output data stream to have
interpretations different from that of the default character
set. See "<span class="italic">Extended Channel
Interpretation Assignments</span>" document (available
from ISO) for a list of channels and there meaning. </p>
<p>The ECI is identified by a 6-digit number which is encoded
according to Table 10: in the ISO 16022:2000 specification. This
is the encodation that is used for the "~7" tilde specification
of the ECI protocol.</p>
</td></tr><tr><td>~9</td><td>
<p>Send the special control code (ASCII=234) so that the reader
will interpret the rest of the symbol as a bar code reader
programming instruction.</p>
</td></tr><tr><td>~dnnn</td><td>
<p>Character value as 3 digits, i.e. ~d142 means ASCII value
142</p>
</td></tr></tbody></table>
</div></div><br class="table-break">
</div>
<div class="sect2" title="Creating different backends"><div class="titlepage"><div><div><h3 class="title"><a name="id2607268"></a>Creating different backends</h3></div></div></div>
<p>In order to create the actual output one or more backends must be created. The
Datamatrix supports the following backends:</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">BACKEND_IMAGE</code>, Create an image backend. This is the
default backend if no explicit backend is specified.</p>
</li><li class="listitem">
<p><code class="code">BACKEND_PS</code>, Create a postscript backend. The text string
that represents the postscript for the barcode is returned directly from
the <code class="code">Backend::Stroke()</code></p>
</li><li class="listitem">
<p><code class="code">BACKEND_EPS</code>, Create an encapsulated postscript
backend</p>
</li><li class="listitem">
<p><code class="code">BACKEND_ASCII</code>, This is a special backend which will
generate an ASCII rendering of the datamatrix barcode. This is mostly
practical for technical investigations regarding the technical structure
of a Datamatrix barcode.</p>
</li></ul></div><p>
</p>
<p>The following code snippet shows two ways of creating a barcode image
backend.</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Create an image backend
$backend = DatamatrixBackendFactory::Create($encoder);</span></pre></td></tr></table></div><p>
</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Create an image backend
$backend = DatamatrixBackendFactory::Create($encoder, BACKEND_IMAGE);</span></pre></td></tr></table></div><p>
</p>
<p>The following code shows a complete script to generate a postscript output</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</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">;
</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">;
</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">
</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">;
</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">
</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">;
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</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">;
</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">;
</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">
</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">;
</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">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
</p>
</div>
<div class="sect2" title="Generic backend methods"><div class="titlepage"><div><div><h3 class="title"><a name="id2607359"></a>Generic backend methods</h3></div></div></div>
<p>The following methods are available to adjust the final look and feel of the
barcode</p>
<p>
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p><code class="code">Backend::SetColor($aOne, $aZero,
$aBackground='white')</code></p>
<p>the color of the 'black' and 'white' modules in the barcode and the
quiet area around the barcode</p>
</li><li class="listitem">
<p><code class="code">Backend::SetQuietZone($aSize)</code></p>
<p>the size of the "quiet zone" in pixels for the image backend and in
points (1 pt = 1/72 inch) for the postscript backend</p>
</li><li class="listitem">
<p><code class="code">Backend::SetModuleWidth($aWidth)</code></p>
<p>the module width specified in pixels for the image backend and in
points (1 pt = 1/72 inch) for the postscript backend</p>
</li><li class="listitem">
<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
if the second parameter is set. For postscript backends the postscript
string is returned directly from the method. (See example above)</p>
</li></ol></div><p>
</p>
</div>
<div class="sect2" title="Image backend methods"><div class="titlepage"><div><div><h3 class="title"><a name="id2607382"></a>Image backend methods</h3></div></div></div>
<p>For the image backend it is possible to adjust the image encoding format with the
following method</p>
<p>
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p><code class="code">Backend::SetImgFormat($aFormat,$aQuality=75)</code></p>
<p>Specify image format. Possible values are </p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">'auto'</code></p>
</li><li class="listitem">
<p><code class="code">'png'</code></p>
</li><li class="listitem">
<p><code class="code">'jpeg'</code></p>
</li><li class="listitem">
<p><code class="code">'gif'</code></p>
</li></ul></div><p>
</p>
<p>For 'jpeg' format the quality parameter is a number in range [1-100]
and specified how much compression / (Data loss) should be used. 100=no
compression. Normal values are in the range [60-95]</p>
<p>The following example sets the image format to 'JPEG' with quality
80.</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</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>
</p>
</li></ol></div><p>
</p>
</div>
<div class="sect2" title="Postscript backend format options"><div class="titlepage"><div><div><h3 class="title"><a name="id2607457"></a>Postscript backend format options</h3></div></div></div>
<p>For postscript backend it is possible to select whether the postscript should be
generated as encapsulated postscript. This is controlled by the method</p>
<p>
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><code class="code">Backend::SetEPS($aFlg=true)</code></p>
</li></ul></div><p>
</p>
</div>
<div class="sect2" title="A template to create barcodes"><div class="titlepage"><div><div><h3 class="title"><a name="id2607560"></a>A template to create barcodes</h3></div></div></div>
<p>In the example directory in the distribution
('<code class="filename">datamatrix/examples</code>') you can find many more examples on
how to create barcodes. As a good start the following (simple) template may be used
as a base for further customizations.</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</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">;
</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">;
</span><span class="hl-var">$shape</span><span class="hl-code"> = </span><span class="hl-identifier">DMAT_AUTO</span><span class="hl-code">;
</span><span class="hl-var">$encoding</span><span class="hl-code"> = </span><span class="hl-identifier">ENCODING_AUTO</span><span class="hl-code">;
</span><span class="hl-var">$modulewidth</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">;
</span><span class="hl-var">$quietzone</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
</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">;
</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">;
</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">;
</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">;
</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">
</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">;
</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">;
</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">
</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">;
</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">
</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">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Set Quiet zone</span><span class="hl-comment"></span><span class="hl-code">
</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">;
</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">
</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">;
</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">
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</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-code">,</span><span class="hl-var">$outputfile</span><span class="hl-brackets">)</span><span class="hl-code">;
</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">
</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">;
</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">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
</p>
</div>
<div class="sect2" title="Sample application"><div class="titlepage"><div><div><h3 class="title"><a name="id2607586"></a>Sample application</h3></div></div></div>
<p>As an example the library includes a WEB-based demo barcode creation application.
This application can be used to easily create barcode through it's WEB interface. It
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
library and not as a finalized product.</p>
<p><a class="xref" href="ch26s02.html#fig.datamatrix-demoapp" title="Figure 26.9. Datamatrix WEB-based demo application">Figure 26.9. Datamatrix WEB-based demo application</a> shows a screen shot of the
application interface.</p>
<div class="figure"><a name="fig.datamatrix-demoapp"></a><p class="title"><b>Figure 26.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"> </td><td width="20%" align="center"><a accesskey="u" href="ch26.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>