Skip to main content

UPC Supplemental 5

  • 2 minutes to read

UPC Supplemental 5 is an extension to a standard UPC barcode that adds a 5-digit supplemental code. It is primarily used in publishing and retail contexts to encode additional information (such as price, issue number, or edition details for books and periodicals).

UPC Supplemental 5, DevExpress Barcode Generation API for Java

Refer to the following page for additional information: https://en.wikipedia.org/wiki/Universal_Product_Code

Configure UPC Supplemental 5 Settings

Use the UPCSupplemental5Options class to configure UPC Supplemental 5 barcode settings.

The following code snippet creates a UPC Supplemental 5 barcode and customizes its encoding parameters:

import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {

        UPCSupplemental5Options options = new UPCSupplemental5Options();
        options.setPadding(new Padding(10));
        options.setShowText(false);
        options.setWidth(150);
        options.setHeight(150);

        Path outputDir = Path.of("output");
        Files.createDirectories(outputDir);

        try (FileOutputStream fileStream = new FileOutputStream(
                outputDir.resolve("upc5.png").toFile());
                BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                    barcodeGenerator.export(
                            "4210000526",
                            fileStream,
                            DXImageFormat.getPng());
        }
    }
}

Fluent API

Use the UPCSupplemental5OptionsBuilder class to configure UPC Supplemental 5 barcode settings with the Fluent API.

The following code snippet creates a UPC Supplemental 5 barcode and customizes its encoding parameters with the Fluent API:

import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {

        UPCSupplemental5Options options = UPCSupplemental5OptionsBuilder.create()
            .withPadding(new Padding(10))
            .withShowText(false)
            .withWidth(150)
            .withHeight(150)
            .build();

        Path outputDir = Path.of("output");
        Files.createDirectories(outputDir);

        try (FileOutputStream fileStream = new FileOutputStream(
                outputDir.resolve("upc5.png").toFile());
                BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                    barcodeGenerator.export(
                            "4210000526",
                            fileStream,
                            DXImageFormat.getPng());
        }
    }
}
See Also