Home Page PDF417 symbol generator for PHP
Home
Help
J4L PDF417 for PHP
Overview
Demonstration
User Guide
Pricing & Ordering

Other barcodes for PHP
Barcode Suites
AztecCode
Barcodes 1D
DataMatrix
GS1 Databar (RSS)
MaxiCode
PDF417
QRCode

For other languages
.NET
ActiveX
AJAX/Javascript
C++
Delphi
Java
PHP
Realbasic
Ruby

Reader/Scanner
J4L Vision
User Guide

Overview

RPDF417 for PHP is a software package that allows you to create PDF417 symbols.

Some of its main features are:

  • You have control over many relevant paramenters in order to customize the resulting bar code image to your particular needs :
  • You can specify the width and height of the bars and the “quite zone” (margins).
  • You can specify the background color, and the color of the bars.
  • You can rotate the image 90,180 or 270 degrees.
  • The resulting image can be sent directly to the browser or to a file, in several formats (PNG, JPEG, GIF, WBMP).
  • Developed using object oriented programing techniques, you can easily modify the source code to adapt your application needs or to add a new bar code type. (Of course you can count on us to do it, in most cases that will be more cost-effective for you).

Requirements

  • A working PHP4 or PHP5 system
  • GD library. It’s usually bundled into PHP.
  • Support for specific image formats such as GIF or JPEG if you want to use them. Default is PNG. In recent PHP versions you will likely have at least PNG and JPEG.

Installation

Create a working directory for the application. It should be OUTSIDE the web server tree (this is, the web server should not access it). We will call it "the application directory".

Uncompress the provided distribution file into the application directory.

Create another working directory INSIDE the web server tree, and configure your web server to process PHP files in it. This is, make sure you can acces this directory using an appropriate URL from your browser, make sure that files with .php extension are parsed through the PHP interpreter, etc. We will call it "the web directory".

Copy the demo.php file from the application directory to the web directory.

Edit the demo.php in the web directory and update the include_path setting to the "inc" subdirectory of the application directory. The sentence is at the beginning of the script. Example :

ini_set("include_path", "/home/myusername/rpdf417php_application/inc" );

Call demo.php using the appropriate URL in your browser and verify it works properly.

Basic Operation

Generating your first bar code.

You can see an example of the mininum coding effort to get up un running by using the provided sample code sample.php.

We reproduce and comment it here to show how it works.

First we set the include_path so PHP will find RPDF417 program files, as we already did for the demo.php file:

ini_set("include_path", "/home/myusername/rpdf417php_application/inc" );

We charge the class file of RPDF417 for PHP:

require( "PDF417_class.inc" );

RPDF417 for PHP uses PHP OOP capabilities in a Java-like style, so prior of executing
any function we must create a barcode object of the proper type. We use the
$bc variable for this.

$bc = new PDF417(); 

We are ready to obtain our barcode graphic. However we will usually wish to specify some parameters. All these settings are optional and if you don’t call the setting functions the program will use its default values. In this example we set the module size to 2 x 8 pixels.

$bc->setBarWidth(2);
$bc->setBarHeight(8);

To show the barcode, we call the paint() function. It receives as parameter the character string containing the code to be shown.

$bc->paint( "string to be encoded" );

Parameter Setting

Although all settings are optional you will usually need to set at least some of the program parameter’s in order to adjust it to your particular needs.

Important: To set any parameter you should use the provided setParameter() functions. You shouldn’t directly set any instance variable as it may lead to unexpected results and incompatibility of your code with future versions of the program  :

$bc->setParam( 2 ); // OK 
$bc->Param = 2; // DON’T DO THIS !!

You can set the following parameters :

Generic Parameters

setQuiteZone( int ) Sets the margin in pixels of the four sides around the graphic. You can also use setTopMargin() & setLeftMargin() instead.

setTopMargin( int ) Sets the vertical margin or empty space between the image’s border and the start of the bars. The bottom margin is se to the same size.

setLeftMargin( int ) Sets the horizontal margin or empty space between the image’s border and the start of the bars. The right margin is set to the same size.

setBGColor( string ) Sets the image’s background color.  It can have two formats :

  1. A descriptive name among the predefined ones. They are: WHITE, RED, GREEN, BLUE, YELLOW, CYAN, ORANGE, GRAY, BLACK.
    ( Note: you may add your own colors editing the source code of Graphics.inc. Just add them to the $stdColors array definition )
  2. The color’s RGB values in a comma-separated string.

Examples:

$bc->setBGColor( “YELLOW” );
$bc->setBGColor( “255,128,255” ); // rose

setBarColor( string ) Sets the color of the bars. Same format than setBGColor()

setRotation( integer ) Sets the rotation of the barcode. Acceptable values are :

  • 0 normal
  • 90 ( vertical, bars drawn from bottom to top )
  • 180 ( inverted )
  • 270 ( vertical, bars drawn from top to bottom )

setImageType( string [, integer] ):

Sets the image type in which the graphic will be generated. Second parameter is the quality (%). It’s optional and should be used only for JPEG.

There are four possible image formats in which the barcode can be generated:

  • PNG: default and recommended format
  • JPEG: note that image size will be much higher. You can reduce it reducing image quality ( second optional parameter in setImageType() ).
  • GIF: note that it was removed from GD version 1.6, so it’s likely that you won’t have it available in recent PHP versions
  • WBMP: note that this is a wireless format so it won’t show on most browsers

Examples:

$bc->setImageType( “GIF” );
$bc->setImageType( “JPEG”, 50 );

setFilePath( string )

Sets the file path where the image files will be created. After calling to this function, subseqüent calls to paint() will create a file instead of sending the image to the browser. By default the output will go to the browser. See  “Image Ouput” paragraph below for more details.

PDF417 specific parameters

setBarWitdh( int ) Sets the module width in pixels.

setBarHeight( int ) Sets the module height in pixels.

setECLevel( int ) Sets the error correction level. Valid values are 0 to 8. Default is 2.

setColumns( int ) Sets the number of data columns to be used. Valid values are 1 to 30. Default is 10. The symbol will have the number of rows necessary to accomodate the data to be encoded, in thisnumber of coulumns.

setCMode( string ) Sets the compression mode. Possible values are 'NUMERIC', 'TEXT' and 'BINARY'. Default is binary. By choosing the right compression mode, you will minimize the symbol size.

MacroPDF parameters

setMacroRows( int ) By setting this parameter you are indicating that you wish to use the macroPDF feature. The program will generate several symbols with the specified rows, as much as needed to accomodate the data to be encoded.

setMacroFileId( int )
setMacroFileName( string )
setMacroFileSize( int )
setMacroTimeStamp( int )
setMacroSender( string )
setMacroAddressee( string )

All these method set the corresponding MacroPDF parameter. They are optional and not used by default.

Image Output

The image that the program generates can be ouput in two ways: to the browser or to a file.

Output to browser

This is the default mode. In the last sentence of the sricpt we call to the paint() method so it will directly output the image to the browser (after appropriate HTTP headers of course). Note that you will usually need an HTML page with a form in it that will set the appropriate parameters. In the example we provide this is done by demo.php. In this mode you will usually generate only one image at a time.

Output to file

Activation

Barcode images can be stored into files. To do so you must first call setFilePath() in order to specify a base directory in your filesystem where the generated files will be stored. Please end it with a slash (“/”). If you want to use the current directory use “./” as path (You can use regular slash as PHP converts it to the backslash in Windows systems) . Note that this call is mandatory as it also works as an indicator that you want the output to a file.

File names

You have two options for the file name the generated image will have:

You can pass the file name you wish as a second optional parameter to the paint() method or you can do nothing so a default filename will be used ( code plug image type extension, e.g. ‘12345678.png’ )

Multiple file generation

When you send the output to a file, you can easily create many barcode images in one program. Just call to the paint() method as many times as you wish.