
Barcodes represent data about an object in a machine‑readable visual form. They are widely used to store product information that can be read by barcode scanners. To generate and read many barcode types in PHP web applications, we released Aspose.BarCode for PHP via Java – a simple PHP barcode generator and reader API that works through the Java Bridge.
In this article you will find recipes and code samples for generating and reading barcodes with PHP. After reading, you will 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
Installing Aspose.BarCode for PHP via Java requires only a few steps. Prerequisites:
Download the full package containing the API JAR, Java Bridge.jar, Java.inc, and ready‑to‑run examples from here. To run the examples:
- Start the JavaBridge server with run-bridge.bat (included in the package).
- Open doc/examples/php_side/how_to_generate_barcode_examples.php in a browser or run it from the command line.
Generate Barcodes using PHP Barcode Generator
After setting up the environment, you can start creating barcodes in your PHP application. Aspose.BarCode for PHP via Java supports many symbologies, including:
- Code128
- Code11
- Code39
- QR
- Datamatrix
- EAN13
- EAN8
- ITF14
- PDF417
- and many more.
To generate a barcode of any supported type:
- Create a BarcodeGenerator object with the desired encoding and text.
- Call the save() method to produce the image.
Output

Generate 2D Barcodes using PHP Barcode Generator
Two‑dimensional barcodes appear as squares or rectangles made of many dots. The API also supports 2D types such as QR and PDF417. The example below creates a QR code in PHP:
Output

Generate Barcodes with a Customized Appearance in PHP
You can customize barcode colors, background, and borders. The following sample shows how to set a custom appearance:
Output

Generate Barcode with Caption in PHP
The API lets you add and style a caption for the barcode. The code below demonstrates how to set a caption and customize its font:
Output

Read a Barcode using PHP Barcode Reader
The same library also provides a powerful barcode reader. To read a barcode:
- Create a BarcodeReader instance with the image path.
- Call read().
- Retrieve the type and text with getCodeTypeName() and getCodeText().
Read Barcode with a Particular Symbology using PHP Barcode Reader
Barcode Recognition identifies the barcode type during scanning. If you know the symbology in advance, you can speed up scanning by specifying it to the reader. The example below reads a barcode of a specific symbology:
Advanced Features of PHP Barcode Generator and Reader API
Aspose.BarCode for PHP via Java offers many advanced features. See the documentation for details and adapt the Java examples 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
If you have questions, feel free to contact us via our forum.