Skip to content

aspose-barcode/Aspose.BarCode-for-Java

Repository files navigation

Aspose.BarCode for Java Examples

This repository contains executable, self-documented TestNG examples for Aspose.BarCode for Java.

The examples demonstrate complete development workflows: configuring barcode data, generating barcode images, recognizing barcodes from different input sources, examining recognition results, validating decoded data, and working with structured complex barcode formats.

Each example is designed to accompany the official Aspose.BarCode for Java documentation and to provide code that can be run, inspected, and adapted for application development.


Documentation

Use the following documentation sections together with the examples in this repository:

Resource Purpose
Aspose.BarCode for Java documentation Main documentation entry point
Getting Started Installation, licensing, system requirements, and initial setup
Developer Guide Detailed generation, recognition, and complex barcode guides
API Reference Java classes, methods, properties, and enumerations
Installation Installing Aspose.BarCode for Java and configuring dependencies
Evaluation and Licensing Applying a license and understanding evaluation limitations
Release Notes Changes, fixes, and new features in each release

Java requirements

Aspose.BarCode for Java supports Java 8 and later.

The examples in this repository require Java 17 or later to compile and run. They may use Java APIs introduced after Java 8, including List.of(...) and Path.of(...).

The repository is configured as a Gradle project and includes the Gradle wrapper. A separate local Gradle installation is not required.


Repository structure

The Java examples are organized under:

src/test/java/com/aspose/barcode/guide/
├── quickstart/
├── generation/
├── recognition/
├── complex/
└── common/

Sample input files and generated output files are stored under:

src/test/resources/

The main example areas are described below.


Quick start examples

Directory:

src/test/java/com/aspose/barcode/guide/quickstart/

The quick start examples provide the shortest complete workflows for first-time users.

QuickGenerationExamples

Demonstrates how to:

  • create a BarcodeGenerator;
  • select an encoding symbology;
  • assign barcode text;
  • generate a barcode image;
  • save the result to a file;
  • verify the generated barcode.

Related documentation:

QuickRecognitionExamples

Demonstrates how to:

  • create a BarCodeReader;
  • read a barcode image;
  • select one or more DecodeType values;
  • iterate through BarCodeResult objects;
  • retrieve recognized text and barcode type.

Related documentation:


Barcode generation examples

Directory:

src/test/java/com/aspose/barcode/guide/generation/

These examples explain how to create barcode images and configure their data, appearance, dimensions, output format, and validation behavior.

Main documentation section:

Generation overview

Directory:

generation/overview/

Provides introductory generation workflows and demonstrates the main steps used by the other generation examples:

  1. select an EncodeTypes value;
  2. provide codetext;
  3. configure generation parameters;
  4. generate or save the barcode image;
  5. recognize the result when verification is required.

Related documentation:

Barcode symbology and codetext

Directory:

generation/symbology_codetext/

Example classes include:

  • SetBarcodeSymbologyAndText
  • SymbologyAndCodeTextExample

These examples demonstrate how to:

  • select a barcode symbology;
  • assign and update codetext;
  • use symbology-specific text formats;
  • generate different barcode types from the same workflow;
  • validate the recognized type and text.

Related documentation:

Appearance

Directory:

generation/appearance/

Example classes include:

  • CustomizeBarcodeAppearance
  • CustomizeCaptionsAndText

These examples demonstrate high-level appearance configuration, including:

  • foreground and background colors;
  • barcode dimensions;
  • text visibility;
  • captions above and below the barcode;
  • caption alignment, padding, and font settings.

Related documentation:

Visual parameters and layout

Directory:

generation/visual_parameters/

This is the most detailed set of visual-generation examples.

Example classes include:

  • BackgroundsExample
  • BordersExample
  • ColorsExample
  • CustomizingCaptionsExample
  • CustomizingSizeExample
  • ImageAndLayoutParametersExample
  • RotationExample
  • TextAndFontExample
  • UseUnitExample
  • VisualParametersAndLayout

The examples demonstrate how to configure:

  • barcode and image colors;
  • image backgrounds;
  • borders and border styles;
  • barcode width and height;
  • padding and quiet zones;
  • X-dimension and bar height;
  • caption position and alignment;
  • human-readable text;
  • font family, size, and style;
  • image rotation;
  • units such as pixels, millimeters, points, and inches;
  • image resolution and layout behavior.

Related documentation:

Barcode size

Directory:

generation/size/

Example class:

  • CustomizeBarcodeSize

Demonstrates how to control:

  • barcode image width and height;
  • X-dimension;
  • bar height;
  • auto-size modes;
  • aspect ratio;
  • padding and quiet zones;
  • resolution-dependent dimensions.

Related documentation:

Unit class

Directory:

generation/unit/

Example class:

  • UnitClassExample

Demonstrates the Unit API and conversion between supported measurement units. These examples are useful when barcode dimensions must be defined in physical units rather than only in pixels.

Related documentation:

X-dimension

Directory:

generation/xdimension/

Example class:

  • XDimensionExamples

Demonstrates how X-dimension affects:

  • module and bar width;
  • final image size;
  • barcode readability;
  • output at different resolutions;
  • conversion between pixel and physical dimensions.

Related documentation:

Checksums

Directory:

generation/checksum/

Example classes include:

  • EnforcedChecksumExamples
  • OptionalChecksumExamples
  • SetBarcodeChecksum

These examples demonstrate the difference between symbologies with:

  • mandatory checksums that are always generated;
  • optional checksums that can be enabled or disabled;
  • reader-side checksum validation;
  • normalized or expanded decoded text;
  • checksum-aware regression tests.

The examples cover common 1D symbologies such as Code 39, Code 93, Code 128, EAN, UPC, Interleaved 2 of 5, Codabar, and other formats with symbology-specific checksum rules.

Related documentation:

Save options

Directory:

generation/save_options/

Example classes include:

  • SaveGeneratedBarcodes
  • SaveGeneratedImageExample

These examples demonstrate how to:

  • save generated barcodes to files;
  • save images to output streams;
  • select an output image format;
  • obtain a generated BufferedImage;
  • use generated barcode images in memory-based workflows.

Related documentation:

Print options

Directory:

generation/print_options/

Example classes include:

  • PrintBarcodes
  • PrintOptionsExample

These examples demonstrate barcode printing workflows, including:

  • rendering a barcode for printing;
  • working with printer graphics;
  • controlling placement and dimensions;
  • preparing barcode images for printed documents and labels.

Related documentation:


Barcode recognition examples

Directory:

src/test/java/com/aspose/barcode/guide/recognition/

These examples demonstrate how to read barcodes, restrict recognition to selected symbologies, work with image regions and input sources, inspect recognition metadata, and tune recognition quality and performance.

Main documentation section:

Choose recognition symbology

Directory:

recognition/choose_symbology/

Example class:

  • ChooseRecognitionSymbology

Demonstrates how to:

  • recognize a specific barcode type;
  • provide several expected DecodeType values;
  • use all supported types when the symbology is unknown;
  • reduce unnecessary recognition work by selecting expected types.

Related documentation:

Input sources

Directory:

recognition/input_sources/

Example class:

  • InputSourcesExamples

Demonstrates how to read barcodes from:

  • image file paths;
  • input streams;
  • byte arrays;
  • BufferedImage objects;
  • application-managed image sources.

Related documentation:

Barcode properties

Directory:

recognition/barcode_properties/

Example classes include:

  • AnglesExample
  • ConfigureSymbologyTypeExample
  • CoordinatesExample
  • ReadingCodeTextExample
  • ReadingCodeTextRawExample
  • ReadingMetadataExample
  • ResultValidationExample

These examples demonstrate how to retrieve and validate:

  • recognized codetext;
  • raw codetext bytes;
  • barcode type;
  • confidence and reading quality;
  • barcode angle;
  • bounding rectangle;
  • quadrangle coordinates;
  • extended recognition parameters;
  • result validity and consistency.

Related documentation:

Region of interest

Directory:

recognition/roi/

Example class:

  • RegionOfInterestExamples

Demonstrates how to:

  • restrict recognition to a selected rectangle;
  • scan several regions independently;
  • improve performance when the barcode location is known;
  • avoid unrelated objects in complex images.

Related documentation:

Quality settings

Directory:

recognition/quality_settings/

Example class:

  • QualitySettingsExample

Demonstrates how recognition quality presets and individual settings affect barcode reading.

Use these examples when balancing:

  • recognition speed;
  • support for damaged or low-quality images;
  • small barcode modules;
  • image complexity;
  • expected barcode quality.

Related documentation:

Performance and difficult images

Directory:

recognition/performance/

Example classes include:

  • DeconvolutionModeExample
  • HighPerformanceModeExample
  • MinimalXDimensionExample
  • MultithreadReadingExample
  • QualityModeExample
  • ReadingColorInvertedExample
  • ReadingDamagedBarcodeExample
  • ReadingLowResolutionBarcodeExample
  • RecognitionPresets

These examples demonstrate how to:

  • select recognition presets;
  • optimize for speed or quality;
  • process several images in parallel;
  • recognize low-resolution barcodes;
  • recognize damaged or blurred symbols;
  • handle inverted barcode colors;
  • configure minimal X-dimension;
  • use deconvolution-related recognition settings.

Related documentation:

Special recognition parameters

Directory:

recognition/special_parameters/

Example classes include:

  • AllowIncorrectBarcodesExample
  • AustralianPostParametersExample
  • ChecksumValidationExample
  • DetectEncodingExample
  • StripFNCExample

These examples demonstrate specialized reader behavior, including:

  • reading barcodes that do not fully satisfy a symbology specification;
  • checksum validation modes;
  • automatic text encoding detection;
  • handling FNC characters;
  • Australian Post decoding parameters.

Related documentation:


Complex barcode examples

Directory:

src/test/java/com/aspose/barcode/guide/complex/

Complex barcodes contain structured business data defined by payment, healthcare, postal, shipping, or identification standards. These examples demonstrate the full workflow:

  1. populate a typed complex codetext model;
  2. generate its carrier barcode;
  3. recognize the carrier symbology;
  4. decode the recognized text into a typed object;
  5. validate individual business fields.

Main documentation section:

Introduction

Directory:

complex/introduction/

Explains the difference between:

  • regular barcode generation with BarcodeGenerator;
  • structured barcode generation with ComplexBarcodeGenerator;
  • raw recognized text;
  • typed decoding through ComplexCodetextReader.

Related documentation:

Generate complex barcodes

Directory:

complex/generate/

Demonstrates how to:

  • create typed business data;
  • generate the standardized payload;
  • configure carrier appearance;
  • save complex barcodes to files or streams;
  • verify generated output.

Related documentation:

Read complex barcodes

Directory:

complex/read/

Demonstrates the two-stage recognition workflow:

  1. recognize the physical carrier barcode;
  2. pass recognized codetext to the matching complex decoder.

The examples also show how to handle unsupported data and null decoder results.

Related documentation:

Supported complex barcode types

Directory:

complex/supported_types/

The examples are grouped by standard.

Directory Structured data demonstrated Related documentation
swiss_qr/ Swiss QR payment data, creditor and debtor addresses, references, and messages Swiss QR Barcodes
hibc/ HIBC LIC product data and HIBC PAS healthcare records HIBC Barcodes
royal_mail_mailmark/ Royal Mail Mailmark 1D and Mailmark 2D postal data Royal Mail Mailmark Barcodes
maxicode/ Structured MaxiCode mode 2 and mode 3 data MaxiCode Barcodes
usa_driver_id/ AAMVA USA Driver ID data stored in PDF417 USA Driver ID Barcodes

The parent documentation page is available here:

Complete complex barcode workflows

Directory:

complex/examples/

Provides complete end-to-end tests that combine:

  • business-object creation;
  • image generation;
  • carrier recognition;
  • structured decoding;
  • field-by-field validation;
  • processing of several complex barcode types.

Related documentation:

Complex barcode troubleshooting

Directory:

complex/troubleshooting/

Demonstrates how to distinguish between:

  • image-recognition failures;
  • carrier-type mismatches;
  • structured-decoding failures;
  • missing required fields;
  • standard-specific range validation errors.

Related documentation:


Common test utilities

Directory:

src/test/java/com/aspose/barcode/guide/common/

The classes in this directory support the examples and are not part of the public Aspose.BarCode API.

ExampleAssist

Provides shared operations such as:

  • creating and checking output paths;
  • validating generated files;
  • recognizing generated images;
  • comparing expected barcode type and text;
  • matching exact text or an expected prefix;
  • applying image transformations;
  • generating degraded images for recognition tests;
  • printing recognition diagnostics.

Expected and CompareMode

Describe the expected recognition result and define how decoded text is compared, for example by exact equality or prefix matching.

ImageSupplier

Provides reusable image-loading behavior for tests that process input images in different forms.

LicenseAssist

Applies an Aspose.BarCode license when one is available.

A license is optional for running the examples. Without a license, the library works in evaluation mode and evaluation limitations may apply.


Prerequisites

Before running the examples, install or provide:

  • JDK 17 or later;
  • Git;
  • internet access for the first dependency resolution;
  • an optional Aspose.BarCode license.

Check the active Java version:

java -version

Check the compiler version:

javac -version

Both commands should report Java 17 or later.


Build and run

This repository is configured with Gradle and includes the Gradle wrapper.

Linux and macOS

Run all tests:

./gradlew clean test

Windows

Run all tests:

gradlew.bat clean test

Run one example class

Linux and macOS:

./gradlew test --tests "com.aspose.barcode.guide.quickstart.QuickGenerationExamples"

Windows:

gradlew.bat test --tests "com.aspose.barcode.guide.quickstart.QuickGenerationExamples"

Run one test method

./gradlew test --tests "fully.qualified.ClassName.methodName"

Replace the package, class, and method names with the example you want to run.

This repository does not include a Maven pom.xml. The documented build commands therefore use the Gradle wrapper.


Run examples from an IDE

To use IntelliJ IDEA, Eclipse, or another Java IDE:

  1. clone the repository;
  2. open or import it as a Gradle project;
  3. select JDK 17 or later as the project SDK;
  4. allow Gradle to resolve dependencies;
  5. run the required TestNG class or method.

The examples are tests, so the IDE must use TestNG when launching them.


Output files and test resources

The examples use the following directory for input resources and generated output:

src/test/resources/

Files are organized by topic so that the output of each example can be inspected after the test completes.

Many generation tests follow this validation pattern:

  1. generate a barcode image;
  2. verify that the file exists and is not empty;
  3. read the generated image with BarCodeReader;
  4. compare the recognized type and codetext with the expected result.

This makes the examples useful both as documentation and as executable regression tests.


Test conventions

When adding or modifying examples, follow these conventions:

  • keep one primary concept per test;
  • use clear class-level and method-level Javadoc;
  • use deterministic file names and dimensions;
  • store test data under src/test/resources;
  • verify generated output through recognition where practical;
  • validate structured fields for complex barcode examples;
  • keep package names lowercase;
  • use ExampleAssist and LicenseAssist where appropriate;
  • do not treat helper methods from common as public Aspose.BarCode API.

Troubleshooting

Gradle reports an unsupported Java version

Confirm that Gradle is using JDK 17 or later:

./gradlew --version

The JVM shown in the output must be Java 17 or later.

Dependencies cannot be resolved

Check internet access, proxy configuration, and access to the configured Maven repositories. Then retry:

./gradlew --refresh-dependencies test

A filtered test is not found

Use the fully qualified TestNG class name:

./gradlew test --tests "com.aspose.barcode.guide.generation.xdimension.XDimensionExamples"

Check the package declaration in the source file if the filter still does not match.

A generated barcode is not recognized

Check:

  • selected DecodeType;
  • X-dimension;
  • bar height;
  • image resolution;
  • quiet zones and padding;
  • foreground/background contrast;
  • checksum settings;
  • recognition quality settings.

Use the diagnostics in ExampleAssist and the related recognition examples when investigating the result.

License-related output or evaluation limitations

Configure the license through LicenseAssist.setupLicense() using the license location expected by your local environment. Do not commit private license files to the repository.


Contributing

When contributing a new example:

  1. place it in the package that matches the related documentation topic;
  2. create a separate TestNG class when the topic is independent;
  3. add detailed Javadoc explaining what the class and every test method demonstrate;
  4. use fixed and reproducible test data;
  5. verify generated output when possible;
  6. add or update the corresponding documentation link in this README;
  7. avoid committing private license files or environment-specific paths.

Additional resources


License

This repository contains example code and tests that use Aspose.BarCode for Java. Review the Aspose licensing terms before using the library in production.


Happy barcoding!

About

Aspose.BarCode for Java Examples

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages