DEV Community

E-iceblue Product Family
E-iceblue Product Family

Posted on

Java generate the barcode without text on the barcode image

This guide will show you how to generate Barcode & QR code with the invisible the textual data using Spire.Barcode for Java.

Installing Spire.barcode jar

If you create a Maven project, you can easily import the jar in your application using the following configurations. For non-Maven projects, download the Barcode jar file and add it as a dependency in your application.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId> e-iceblue </groupId>
        <artifactId>spire.barcode</artifactId>
        <version>4.1.2</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Generate a 1D barcode without the Text Data When Creating a Barcode

import com.spire.barcode.BarCodeGenerator;
import com.spire.barcode.BarCodeType;
import com.spire.barcode.BarcodeSettings;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class CreateBarcode {
    public static void main(String[] args) throws IOException {
        //Instantiate BarcodeSettings object
        BarcodeSettings settings = new BarcodeSettings();
        //Set the Barcode type
        settings.setType(BarCodeType.Codabar);
        //Set the Barcode data
        settings.setData("123456789");
        //Make the textual data invisible
        settings.setShowText(false);
        //Make the textual data visible at the Barcode
        settings.setShowTextOnBottom(true);
        //Set width for the black and white stripes
        settings.setX(0.8f);
        //Set height for the created Barcode image
        settings.setImageHeight(50);
        //Set width for the created Barcode image
        settings.setImageWidth(70);
        //Make the border visible
        settings.hasBorder(true);
        //Set the border color
        settings.setBorderColor(new Color(135,206,250));
        settings.setBorderWidth(1);
        settings.setBackColor(new Color(240,255,255));

        //Instantiage BarCodeGenerator object
        BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
        //Generate image data based on settings and save it to BufferedImage instance
        BufferedImage bufferedImage = barCodeGenerator.generateImage();
        //Save the Barcode as PNG
        ImageIO.write(bufferedImage, "png", new File("Codabar.png"));
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:
1D barcode

Generate a QR code without the Text Data When Creating a Barcode

import com.spire.barcode.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class CreateQR {
    public static void main(String[] args) throws IOException {

        //Instantiate BarcodeSettings object
        BarcodeSettings settings = new BarcodeSettings();
        //Set Barcode type as QR code
        settings.setType(BarCodeType.QR_Code);
        //Set the data 
        settings.setData("Hello 123456789");
        // Make the textual data invisible
        settings.setShowText(false);
        settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);
        settings.setImageWidth(50);
        settings.setImageHeight(50);
        settings.setX(3.0f);
        settings.setQRCodeECL(QRCodeECL.H);
        //make the border invisible
        settings.hasBorder(false);
        //Instantiage BarCodeGenerator object
        BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
        //Generate image data based on settings and save it to BufferedImage instance
        BufferedImage bufferedImage = barCodeGenerator.generateImage();
         //Save the QR code as PNG
        ImageIO.write(bufferedImage, "png", new File("QRCode.png"));
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

QRcode

Top comments (0)