Introduction
PDF417 code comes from the 2D barcode family. You can encode a large amount of information within a single barcode.
All the ASCII characters from 0 to 255 are supported. PDF417 encodes the data differently based on the type of characters provided. Some characters are encoded with a higher compression level. See the compression level on the overview page.
Since version 2.2.0, the class analyzes automatically the data that you provide and chooses the smallest code to output.
This class inherits the BCGBarcode2D class.
Example
BCGpdf417's Methods
- getQuietZone() — Gets if the quiet zone will be drawn
- setQuietZone($quietZone) — Specifies to draw a quiet zone around the barcode
- getCompact() — Gets if the barcode will be compact/truncated
- setCompact($compact) — Specifies if the barcode must be compact/truncated
- getColumn() — Gets the number of data column
- setColumn($column) — Sets the number of data column
- getErrorLevel() — Gets the error correction level of the barcode
- setErrorLevel($errorLevel) — Sets the error correction level of the barcode
- getRatio() — Gets the ratio for printing
- setRatio($ratio) — Sets the ratio for printing
BCGBarcode2D's Methods
- setScaleX($scaleX) — Sets the scaling X for the barcode
- setScaleY($scaleY) — Sets the scaling Y for the barcode
BCGBarcode's Methods
- parse($text) — Analyzes a $text message to draw afterwards
- draw($im) — Draws the barcode on the $im
- getDimension($w, $h) — Returns an array containing the required size for the image
- getScale() — Gets the scale of the barcode
- setScale($x) — Sets the scale of the barcode
- getForegroundColor() — Gets the color of the spaces
- setForegroundColor($color) — Sets the color of the spaces
- getBackgroundColor() — Gets the color of the bars
- setBackgroundColor($color) — Sets the color of the bars
- setColor($fg, $bg) — Sets the color of the bars and spaces
- getOffsetX() — Gets the X offset
- setOffsetX($v) — Sets the X offset
- getOffsetY() — Gets the Y offset
- setOffsetY($v) — Sets the Y offset
- addLabel($label) — Adds a label to the graphic
- removeLabel($label) — Removes a label from the graphic
- clearLabels() — Removes the labels from the graphic
Code Example
<?php require('BCGColor.php'); require('BCGDrawing.php'); require('BCGpdf417.barcode2d.php'); // PDF417 Part $code = new BCGpdf417(); $code->setScale(3); $code->setErrorLevel(2); $code->setCompact(false); $code->setQuietZone(true); $code->parse('PDF 417'); // Drawing Part $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); ?>
Methods Explanation
-
getQuietZone()
— Gets if the quiet zone will be drawn DescriptionGets if the quiet zone will be drawnReturnsbool - true if activated, false otherwise
-
setQuietZone($quietZone)
— Specifies to draw a quiet zone around the barcode DescriptionTo be read correctly, the PDF417 must have a quiet zone around the image. You can, however, turn this off.
The default value is true. -
getCompact()
— Gets if the barcode will be compact/truncated DescriptionGets if the barcode will be compact/truncated.Returnsbool - true if compact/truncated
-
setCompact($compact)
— Specifies if the barcode must be compact/truncated DescriptionCuts the barcode by removing the 2 last columns on the right. Your barcode will be smaller but harder to read.
The default value is false. -
getColumn()
— Gets the number of data column DescriptionGets the number of columns.Returnsint
-
setColumn($column)
— Sets the number of data column DescriptionSpecifies the number of data columns you want to write. You can spread your data more horizontally than vertically by modifying this parameter.
The number of columns must be between 1 and 30.
Setting the value to -1 makes the barcode calculate this number automatically and optimize it.
The default value is -1. -
getErrorLevel()
— Gets the error correction level of the barcode DescriptionGets the error level.Returnsint
-
setErrorLevel($errorLevel)
— Sets the error correction level of the barcode DescriptionThis is the error correction level which allows you to detect and correct errors in the barcode.
The level must be between 0 and 8.
Setting this value calculates the error level automatically by trying to obtain optimal error detection.The number of keywords you write will be restricted depending on the error level you choose. See the overview for more information.
The default value is -1. -
getRatio()
— Gets the ratio for printing DescriptionGets the ratio for printing.Returnsint
-
setRatio($ratio)
— Sets the ratio for printing DescriptionSets the ratio for printing. This is used only if the number of columns is chosen automatically since this parameter will affect the number of columns in your barcode.
If the number is under 1, the barcode will be spread more horizontally.
The default value is 1. -
setScaleX($scaleX)
— Sets the scaling X for the barcode DescriptionThe width in pixel of one module.
The default value is 1.
Note that this method is public. -
setScaleY($scaleY)
— Sets the scaling Y for the barcode DescriptionThe height in pixel of one module.
The default value is 1.
Note that this method is public. -
parse($text)
— Analyzes a $text message to draw afterwards DescriptionThe data you pass to the $text argument must be supported by the type of barcode you use.
Check each barcode's introduction section to obtain more information on how to use this method within each symbology. -
draw($im)
— Draws the barcode on the $im DescriptionThe value of the $im argument must be a GD2 image resource. The size of the image can be defined by the value received from getDimension().
-
getDimension($w, $h)
— Returns an array containing the required size for the image DescriptionReturns an array in which the first index is the image width and the second index is the image height.
The arguments are used to specify the starting point of the drawing. Should be 0 for both.
The BCGDrawing class uses this method to create the image resource.Returnsarray(int, int) - [0] is the width, [1] is the height -
getScale()
— Gets the scale of the barcode DescriptionGets the scale of the barcode. The value is the number of the "smallest" unit in pixel.Returnsint - value in pixels
-
setScale($x)
— Sets the scale of the barcode DescriptionThe barcode will be $x times bigger. Then a pixel will be $x by $x for its size.
-
getForegroundColor()
— Gets the color of the spaces DescriptionGets the color of the spaces of the barcode.Returns
- setForegroundColor($color) — Sets the color of the spaces
-
getBackgroundColor()
— Gets the color of the bars DescriptionGets the color of the bars of the barcode.Returns
- setBackgroundColor($color) — Sets the color of the bars
-
setColor($fg, $bg)
— Sets the color of the bars and spaces DescriptionAn easy and fast method to set the color of the bars and spaces. Check the setForegroundColor() and setBackgroundColor().
-
getOffsetX()
— Gets the X offset DescriptionGets the X offset of the barcode in pixels. The value isn't multiplied by the scale.Returnsint - value in pixels
-
setOffsetX($v)
— Sets the X offset DescriptionSpecifies the X offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
-
getOffsetY()
— Gets the Y offset DescriptionGets the Y offset of the barcode in pixels. The value isn't multiplied by the scale.Returnsint - value in pixels
-
setOffsetY($v)
— Sets the Y offset DescriptionSpecifies the Y offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
-
addLabel($label)
— Adds a label to the graphic DescriptionAdds a BCGLabel object to the drawing.
-
removeLabel($label)
— Removes a label from the graphic DescriptionRemoves a specific BCGLabel object from the drawing.
-
clearLabels()
— Removes the labels from the graphic DescriptionClears the BCGLabel objects from the drawing.
