Barcodes are used to visually represent the data about an object in the machine-readable form. It is more popular to keep the data about products which can be read using the barcode scanners. In order to make it possible to generate and read a variety of barcodes in the PHP based web applications, we have released Aspose.BarCode for PHP via Java - an easy to use PHP barcode generator and reader API which is designed to work via Java Bridge.
In this article, I will present the recipes and code samples of how to generate and read the barcodes using PHP in your web applications. After reading this article, you’ll be able to:
- generate a barcode using PHP barcode generator
- generate 2D barcodes such as QR using PHP
- create barcodes with a customized appearance in PHP
- generate barcodes with a caption using PHP
- scan and read a barcode using PHP barcode reader
- scan and read a barcode with a particular symbology in PHP
PHP Barcode Generator and Reader - Installation and Usage
The installation of Aspose.BarCode for PHP via Java consists of a few simple steps. The following are the pre-requisites of the API:
You can download the complete package containing the API’s JAR file, Java Bridge.jar, Java.inc, and ready to run source code examples to read, generate and recognize barcodes using PHP. In order to run the examples, following the below steps:
- Run JavaBridge server using run-bridge.bat (available in the package).
- Open doc/examples/php_side/how_to_generate_barcode_examples.php in the browser or run it using the command line.
Generate Barcodes using PHP Barcode Generator
Once you have set up the environment, you can begin working with barcodes in your PHP based application. Aspose.BarCode for PHP via Java supports a variety of barcode symbologies including:
- and many more.
The following is the simple recipe to generate a barcode of any supported symbology using PHP:
- Create an object of BarcodeGenerator class and initialized it with the desired encoding type and code text.
- Generate barcode using BarcodeGenerator->save() method.
The following code sample shows how to generate a barcode using PHP.
Generate 2D Barcodes using PHP Barcode Generator
Two-dimensional barcodes are represented as squares or the rectangles containing multiple dots. Aspose.BarCode for PHP via Java also supports various 2D barcode types such as QR, PDF417, etc. The following code sample shows how to generate a QR barcode using PHP:
Generate Barcodes with a Customized Appearance in PHP
Aspose.BarCode for PHP via Java also lets you customize the appearance of the barcodes. For example, you can set the background, foreground or border color of the barcode. The following code sample shows how to generate a barcode with a customized appearance in PHP.
Generate Barcode with Caption in PHP
You can also set as well as customize the appearance of the barcode’s caption. The following code sample shows how to set the barcode’s caption and customize its font.
Read a Barcode using PHP Barcode Reader
Along with the barcode generator, the API also provides you a powerful barcode reader to scan the barcodes and extract the data. The following is the recipe for how to read a barcode.
- Create an instance of BarcodeReader and initialize it with the file’s path.
- Read barcode using BarcodeReader->read() method.
- Get barcode type and text using BarcodeReader->getCodeTypeName() and BarcodeReader->getCodeText() methods.
The following code sample shows how to read a barcode using PHP.
Read Barcode with a Particular Symbology using PHP Barcode Reader
Barcode Recognition is the process of identifying the type of barcode we want to scan or read. In the previous example, we simply read a barcode without knowing its symbology type. However, in some cases, we know about the symbology of the barcode in advance. In such a scenario, we can speed up the scanning process by providing the barcode symbology explicitly to the barcode reader.
The following code sample shows how to read a barcode of a specific symbology using PHP.
Advanced Features of PHP Barcode Generator and Reader API
Aspose.BarCode for PHP via Java provides a wide range of features for manipulating barcodes using PHP. You may have a look at the following documentation articles and simply port the Java code to PHP.
- 2D Barcode Features
- Set Height of Bars in Barcode
- Use Checksum and Supplement Data for Barcodes
- Generate a Patch Code
- Working with Barcode Image
- Optimize Barcode Scanning
- Advanced Barcode Recognition Features
In case you would find anything confusing or difficult for you, feel free to contact us via our forum.