RPDF417 for PHP is a software package that allows you to create PDF417 symbols.
Some of its main features are:
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.
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" );If you want the image to be stored into a file or you want to create several images at a time, see the multisample.php script and the output to file section below.
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 :
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 :
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 :
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:
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.
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.
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.
The image that the program generates can be ouput in two ways: to the browser or to a file.
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.
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.
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’ )
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.