PHP Barcode Generator Library

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:

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:

  1. Create a BarcodeGenerator object with the desired encoding and text.
  2. Call the save() method to produce the image.

Output

PHP Barcode Generator

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

QR Code Generator in PHP

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 in PHP

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

PHP Barcode Library

Read a Barcode using PHP Barcode Reader

The same library also provides a powerful barcode reader. To read a barcode:

  1. Create a BarcodeReader instance with the image path.
  2. Call read().
  3. 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:

If you have questions, feel free to contact us via our forum.

See Also