Skip to main content

BarcodeOptionsBuilder<TOptions,TBuilder> Class

The base class for all barcode options builders in the DevExpress Barcode Generation API.

Declaration

public abstract class BarcodeOptionsBuilder<TOptions,TBuilder> extends JavaObject

Type Parameters

Name Description
TOptions

The type of barcode options to configure.

TBuilder

The type of the builder class.

Remarks

Use BarcodeOptionsBuilder to configure barcode settings through chained method calls and create an options object.

Use the build() method to generate an instance of the corresponding BarcodeOptions descendant.

Refer to the following help topic for additional information: QR Code.

The following code snippet creates a QR Code 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 {

        byte[] logoBytes = Files.readAllBytes(Path.of("images/devexpress-logo.png"));

        try (DXImage logo = DXImage.fromStream(new ByteArrayInputStream(logoBytes))) {
            // Customize QR Code frame parameters.
            RectangleQRFrameOptions frameOptions = new RectangleQRFrameOptions();
            frameOptions.setPadding(new Padding(10));
            frameOptions.setFrameColor(Color.getOrange());
            frameOptions.setFrameWidth(10);
            frameOptions.setText("DevExpress");
            frameOptions.setCornerRadius(10);
            frameOptions.setTextAlignment(QRFrameTextAlignment.CENTER);
            frameOptions.setTextColor(Color.getBlack());
            frameOptions.setTextPosition(QRFrameTextPosition.BOTTOM);

            // Customize QR Code parameters.
            QRCodeOptions options = QRCodeOptionsBuilder.create()
                .withErrorCorrectionLevel(QRCodeErrorCorrectionLevel.H)
                .withCompactionMode(QRCodeCompactionMode.AUTO)
                .withVersion(QRCodeVersion.VERSION_10)
                .withIncludeQuietZone(true)
                .withFrameOptions(frameOptions)
                .withLogo(logo)
                .withPadding(new Padding(10))
                .withModuleSize(10)
                .withShowText(false)
                .build();

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

            try (FileOutputStream fileStream = new FileOutputStream(
                    outputDir.resolve("qrcode.png").toFile());
                    BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                        barcodeGenerator.export(
                                "https://www.devexpress.com",
                                fileStream,
                                DXImageFormat.getPng());
            }
        }
    }
}

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
BarcodeOptionsBuilder<TOptions,TBuilder>

Methods

build() Method

Creates a barcode options object with the specified settings.

Declaration

public TOptions build()

Returns

Type Description
TOptions

A barcode options object.

withBackColor(Color backColor) Method

Specifies the background color for the barcode and returns the builder object.

Declaration

public TBuilder withBackColor(Color backColor)

Parameters

Name Type Description
backColor Color

The background color to apply to the barcode.

Returns

Type Description
TBuilder

The builder object with the updated background color.

withBarHeight(float barHeight) Method

Specifies the barcode’s bar height and returns the builder object.

Declaration

public TBuilder withBarHeight(float barHeight)

Parameters

Name Type Description
barHeight float

The barcode’s bar height.

Returns

Type Description
TBuilder

The builder object with the updated bar height.

withBorderColor(Color borderColor) Method

Specifies the barcode border color and returns the builder object.

Declaration

public TBuilder withBorderColor(Color borderColor)

Parameters

Name Type Description
borderColor Color

The barcode border color.

Returns

Type Description
TBuilder

The builder object with the updated border color.

withBorderDashStyle(BorderDashStyle borderDashStyle) Method

Specifies the dash style for the barcode border and returns the builder object.

Declaration

public TBuilder withBorderDashStyle(BorderDashStyle borderDashStyle)

Parameters

Name Type Description
borderDashStyle BorderDashStyle

The barcode border’s dash style.

Returns

Type Description
TBuilder

The builder object with the updated border’s dash style.

withBorderStyle(BorderStyle borderStyle) Method

Specifies the border style for the barcode and returns the builder object.

Declaration

public TBuilder withBorderStyle(BorderStyle borderStyle)

Parameters

Name Type Description
borderStyle BorderStyle

The border style to apply to the barcode.

Returns

Type Description
TBuilder

The builder object with the updated border style.

withBorderWidth(float borderWidth) Method

Specifies the border width of the bar code image and returns the builder object.

Declaration

public TBuilder withBorderWidth(float borderWidth)

Parameters

Name Type Description
borderWidth float

Border width.

Returns

Type Description
TBuilder

The builder object with the updated border width.

withCodeTextHorizontalAlignment(DXStringAlignment alignment) Method

Specifies the horizontal alignment of the bar code text within the bar code image and returns the builder object.

Declaration

public TBuilder withCodeTextHorizontalAlignment(DXStringAlignment alignment)

Parameters

Name Type Description
alignment DXStringAlignment

Horizontal alignment type.

Returns

Type Description
TBuilder

The builder object with the updated horizontal alignment.

withCodeTextVerticalAlignment(DXStringAlignment alignment) Method

Specifies the vertical alignment of the bar code text within the bar code image and returns the builder object.

Declaration

public TBuilder withCodeTextVerticalAlignment(DXStringAlignment alignment)

Parameters

Name Type Description
alignment DXStringAlignment

Vertical alignment type.

Returns

Type Description
TBuilder

The builder object with the updated vertical alignment.

withDpi(float dpi) Method

Specifies the dpi value used to render the bar code.

Declaration

public TBuilder withDpi(float dpi)

Parameters

Name Type Description
dpi float

The dpi value used to create the bar code image.

Returns

Type Description
TBuilder

The builder object with the updated dpi value.

withFooter(BarcodeLabel footer) Method

Specifies the footer label for the barcode and returns the builder object.

Declaration

public TBuilder withFooter(BarcodeLabel footer)

Parameters

Name Type Description
footer BarcodeLabel

The footer label to display below the barcode.

Returns

Type Description
TBuilder

The builder object with the updated footer label.

withFooter(String text) Method

Specifies the footer text for the barcode and returns the builder object.

Declaration

public TBuilder withFooter(String text)

Parameters

Name Type Description
text String

The footer text to display below the barcode.

Returns

Type Description
TBuilder

The builder object with the updated footer text.

withForeColor(Color foreColor) Method

Specifies the foreground color for the barcode and returns the builder object.

Declaration

public TBuilder withForeColor(Color foreColor)

Parameters

Name Type Description
foreColor Color

The foreground color to apply to the barcode.

Returns

Type Description
TBuilder

The builder object with the updated foreground color.

withHeader(BarcodeLabel header) Method

Specifies the header label for the barcode and returns the builder object.

Declaration

public TBuilder withHeader(BarcodeLabel header)

Parameters

Name Type Description
header BarcodeLabel

The header label to display above the barcode.

Returns

Type Description
TBuilder

The builder object with the updated header label.

withHeader(String text) Method

Specifies the header text for the barcode and returns the builder object.

Declaration

public TBuilder withHeader(String text)

Parameters

Name Type Description
text String

The header text to display above the barcode.

Returns

Type Description
TBuilder

The builder object with the updated header text.

withHeight(float height) Method

Specifies the height of the barcode image and returns the builder object.

Declaration

public TBuilder withHeight(float height)

Parameters

Name Type Description
height float

The height of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated height.

withMargin(int all) Method

Specifies the margin for the barcode image and returns the builder object.

Declaration

public TBuilder withMargin(int all)

Parameters

Name Type Description
all int

The margin value to apply to all sides of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated margin.

withMargin(int left, int top, int right, int bottom) Method

Specifies the margin for each side of the barcode image and returns the builder object.

Declaration

public TBuilder withMargin(int left, int top, int right, int bottom)

Parameters

Name Type Description
left int

The margin for the left side of the barcode image.

top int

The margin for the top side of the barcode image.

right int

The margin for the right side of the barcode image.

bottom int

The margin for the bottom side of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated margins.

withMargin(Padding margin) Method

Specifies the margin for each side of the barcode image and returns the builder object.

Declaration

public TBuilder withMargin(Padding margin)

Parameters

Name Type Description
margin Padding

The margin to apply to each side of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated margins.

withModuleSize(float moduleSize) Method

Specifies the module size for the barcode and returns the builder object.

Declaration

public TBuilder withModuleSize(float moduleSize)

Parameters

Name Type Description
moduleSize float

The module size to apply to the barcode.

Returns

Type Description
TBuilder

The builder object with the updated module size.

withPadding(int all) Method

Specifies the padding for the barcode image and returns the builder object.

Declaration

public TBuilder withPadding(int all)

Parameters

Name Type Description
all int

The padding value to apply to all sides of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated padding.

withPadding(int left, int top, int right, int bottom) Method

Specifies the padding for each side of the barcode image and returns the builder object.

Declaration

public TBuilder withPadding(int left, int top, int right, int bottom)

Parameters

Name Type Description
left int

The left padding.

top int

The top padding.

right int

The right padding.

bottom int

The bottom padding.

Returns

Type Description
TBuilder

The builder object with the updated padding.

withPadding(Padding padding) Method

Specifies the same padding for all sides of the barcode image and returns the builder object.

Declaration

public TBuilder withPadding(Padding padding)

Parameters

Name Type Description
padding Padding

The padding to apply inside the barcode image boundaries.

Returns

Type Description
TBuilder

The builder object with the updated padding.

withRightToLeft(boolean rightToLeft) Method

Specifies whether the barcode text is rendered from right to left and returns the builder object.

Declaration

public TBuilder withRightToLeft(boolean rightToLeft)

Parameters

Name Type Description
rightToLeft boolean

true to render the barcode text from right to left; otherwise, false.

Returns

Type Description
TBuilder

The builder object with the updated right-to-left setting.

withRotationAngle(float rotationAngle) Method

Specifies the rotation angle for the barcode image and returns the builder object.

Declaration

public TBuilder withRotationAngle(float rotationAngle)

Parameters

Name Type Description
rotationAngle float

The rotation angle, in degrees, to apply to the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated rotation angle.

withShowText(boolean showText) Method

Specifies whether to display the barcode text and returns the builder object.

Declaration

public TBuilder withShowText(boolean showText)

Parameters

Name Type Description
showText boolean

true to display the barcode text; otherwise, false.

Returns

Type Description
TBuilder

The builder object with the updated text display setting.

withSides(BorderSide sides) Method

Specifies which sides of the barcode image have borders and returns the builder object.

Declaration

public TBuilder withSides(BorderSide sides)

Parameters

Name Type Description
sides BorderSide

The sides of the barcode image to display borders on.

Returns

Type Description
TBuilder

The builder object with the updated border sides.

withSize(float width, float height) Method

Specifies the width and height of the barcode image and returns the builder object.

Declaration

public TBuilder withSize(float width, float height)

Parameters

Name Type Description
width float

The width of the barcode image.

height float

The height of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated size.

withSize(SizeF size) Method

Specifies the size of the barcode image and returns the builder object.

Declaration

public TBuilder withSize(SizeF size)

Parameters

Name Type Description
size

The size to apply to the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated size.

withSizeMode(SizeMode sizeMode) Method

Specifies the size mode for the barcode image and returns the builder object.

Declaration

public TBuilder withSizeMode(SizeMode sizeMode)

Parameters

Name Type Description
sizeMode SizeMode

The size mode to apply to the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated size mode.

Remarks

The following code snippet creates a QR Code barcode and customizes its encoding parameters with the Fluent API:

package barcodes;

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

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

public class Main {
    public static void main(String[] args) throws Exception {
        // Customize QR Code parameters.
        QRCodeOptions options = QRCodeOptionsBuilder.create()
            .withErrorCorrectionLevel(QRCodeErrorCorrectionLevel.H)
            .withCompactionMode(QRCodeCompactionMode.AUTO)
            .withVersion(QRCodeVersion.VERSION_10)
            .withSizeMode(SizeMode.BARCODE_IMAGE)
            .withWidth(300)
            .withHeight(300)
            .build();

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

        try (FileOutputStream fileStream = new FileOutputStream(
                outputDir.resolve("qrcode.png").toFile());
             BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
            barcodeGenerator.export(
                    "https://www.devexpress.com",
                    fileStream,
                    DXImageFormat.getPng());
        }
    }
}

Note

When using BARCODE_IMAGE, the barcode is rendered as an image. In this mode, the barcode’s width and height are mandatory scaling parameters. They define the size of the resulting barcode image in pixels.

withTextFont(DXFont textFont) Method

Specifies the font for the barcode text and returns the builder object.

Declaration

public TBuilder withTextFont(DXFont textFont)

Parameters

Name Type Description
textFont DXFont

The font to apply to the barcode text.

Returns

Type Description
TBuilder

The builder object with the updated text font.

withTextRenderingHint(DXTextRenderingHint textRenderingHint) Method

Sets the text rendering quality.

Declaration

public TBuilder withTextRenderingHint(DXTextRenderingHint textRenderingHint)

Parameters

Name Type Description
textRenderingHint DXTextRenderingHint

The text rendering quality.

Returns

Type Description
TBuilder

The builder object with the updated text rendering quality.

withUnit(DXGraphicsUnit unit) Method

Specifies the measurement unit for the barcode image and returns the builder object.

Declaration

public TBuilder withUnit(DXGraphicsUnit unit)

Parameters

Name Type Description
unit DXGraphicsUnit

The measurement unit to apply to the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated measurement unit.

withWidth(float width) Method

Specifies the width of the barcode image and returns the builder object.

Declaration

public TBuilder withWidth(float width)

Parameters

Name Type Description
width float

The width of the barcode image.

Returns

Type Description
TBuilder

The builder object with the updated width.

withWordWrap(boolean wordWrap) Method

Specifies whether word wrap is enabled for the barcode text and returns the builder object.

Declaration

public TBuilder withWordWrap(boolean wordWrap)

Parameters

Name Type Description
wordWrap boolean

true to enable word wrap for the barcode text; otherwise, false.

Returns

Type Description
TBuilder

The builder object with the updated word wrap setting.