Skip to main content

UPC Supplemental 2

  • 2 minutes to read

UPC Supplemental 2 is an extension to a standard UPC barcode that adds a 2-digit supplement code. This supplement does not replace the primary product identifier. It supplies additional information (such as issue numbers for magazines, newspapers, and other periodicals).

UPC Supplemental 2, 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 2 Settings

Use the UPCSupplemental2Options class to configure UPC Supplemental 2 barcode settings.

The following code snippet creates a UPC Supplemental 2 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 {

        UPCSupplemental2Options options = new UPCSupplemental2Options();
        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("upc2.png").toFile());
                BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                    barcodeGenerator.export(
                            "4210000526",
                            fileStream,
                            DXImageFormat.getPng());
        }
    }
}

Fluent API

Use the UPCSupplemental2OptionsBuilder class to configure UPC Supplemental 2 barcode settings with the Fluent API.

The following code snippet creates a UPC Supplemental 2 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 {

        UPCSupplemental2Options options = UPCSupplemental2OptionsBuilder.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("upc2.png").toFile());
                BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                    barcodeGenerator.export(
                            "4210000526",
                            fileStream,
                            DXImageFormat.getPng());
        }
    }
}
See Also