25.6. A template to create barcodes

In the example directory in the distribution ('pdf417/examples') 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.

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
<?php
require_once('jpgraph/pdf417/jpgraph_pdf417.php');
 
$data = 'PDF-417';
 
// Specification for barcode
 
$columns = 8;   // Use 8 data (payload) columns
$errlevel = 4;  // Use error level 4
$modwidth = 2;  // Setup module width (in pixels)
$height = 2;    // Height factor (=2)
$truncated = false; // Don't truncate 
$showtext = false;  // Show human readable string
 
// Create a new encoder and backend to generate images
try {
    $encoder = new PDF417Barcode($columns,$errlevel);
    $encoder->SetTruncated ($truncated); 
    $backend = PDF417BackendFactory::Create(BACKEND_IMAGE,$encoder);
    $backend->SetModuleWidth($modwidth);
    $backend->SetHeight($height);
    $backend->NoText(!$showtext);
    $backend->Stroke($data);
}
catch(JpGraphException $e) {
    echo 'PDF417 Error: '.$e->GetMessage();
}
?>