1

I have written a code which can generate a bar-code with respect to String codeText = "1104006"; and also can read data from that bar-code. But the problem is, while generating a bar-code below the bar-code it also write the text (codeText). How can I remove the human readable text, circled red in example?

example output with human readable circled in red

public class Main { private static String strBarFolder = ("C:\\Users\\Jobayer__\\Desktop\\"); public static void main(String[] args) { String codeText = "1104006"; String strImageFile = ("barcode.jpg"); BarCodeBuilder builder = new BarCodeBuilder(Symbology.CODE39STANDARD, codeText); builder.save(strBarFolder + strImageFile); System.out.println("Successfully Done"); Image img = Toolkit.getDefaultToolkit().getImage(strBarFolder + strImageFile); BarCodeReader reader = new BarCodeReader(img, BarCodeReadType.Code39Standard); while(reader.read()){ System.out.println("Code Text Found: " + reader.getCodeText()); } reader.close(); } } 
1
  • As an aside, to get a sharper image you should use a lossless format such as PNG instead of JPG. This is also likely to make a smaller file because of the nature of the image. Commented Aug 16, 2016 at 16:09

3 Answers 3

1

Set this property:

builder.CodeLocation = CodeLocation.None; 

Setting CodeLocation to None will hide the barcode text thus creating the effect of barcode without any value in it.

from Aspose support forum: https://forum.aspose.com/t/creating-2d-bar-code-using-aspose-and-merging-it-in-pdf/7265

if you want to change caption text use this property...

builder.Display2DText = "this is caption text"; 

By default if it's set to empty string it displays codetext.

Sign up to request clarification or add additional context in comments.

1 Comment

Code Location done the trick for me but with version 21.9 of Aspose.Barcode the code needed is slightly different: var generator = new Aspose.BarCode.Generation.BarcodeGenerator(Aspose.BarCode.Generation.EncodeTypes.Code128, "1234"); generator.Parameters.Barcode.CodeTextParameters.Location = Aspose.BarCode.Generation.CodeLocation.None;
0

Get into the Aspose source code (if it's allowable) and comment out the drawString() method which is drawing the text to the image OR modify the bar code image by drawing a white rectangle with fillRect() over the text area(s) of the image.

Below is a small runnable console application I quickly whipped up that performs the latter. It is based off of the Bar Code image you provided:

package barcodetextcoverup; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.File; import java.io.IOException; import java.util.Scanner; import javax.imageio.ImageIO; public class BarCodeTextCoverUp { public static void main(String[] args) { startTextCover(); } private static void startTextCover() { Scanner scnr = new Scanner(System.in); String userInput = ""; while (!userInput.equalsIgnoreCase("quit")) { System.out.println("\nEnter the path and file name to the Bar Code image file\n" + "to modify or enter quit to exit:"); userInput = scnr.nextLine(); if (userInput.equalsIgnoreCase("quit")) { break; } // opening a bar code image from disk BufferedImage src = null; try { src = ImageIO.read(new File(userInput)); int iWidth = src.getWidth(); int iHeight = src.getHeight(); // Modify the image... Graphics2D g2 = src.createGraphics(); g2.setColor(Color.WHITE); //Cover the text: Aspose.Demo g2.fillRect(0, 0, 150, 30); // Cover the codeText at bottom of Bar Code g2.fillRect((iWidth/2) - 75, iHeight - 40, 150, 35); g2.dispose(); System.out.println("\nEnter a NEW path and file name for the modified Bar Code image.\n" + "You can use the same file name just change the extention to .png:"); userInput = scnr.nextLine(); // If nothing is supplied then the modifications are not saved. if (!userInput.equals("")) { ImageIO.write((RenderedImage) src, "PNG", new File(userInput)); } System.out.println("----------------------------------------------------------------------"); } catch (IOException ex) { } } } } 

Comments

0

Read the properties of bar-code methods in the below link http://barbecue.sourceforge.net/apidocs/net/sourceforge/barbecue/Barcode.html

Using the setDrawingText(Boolean) default method we remove the text in below bar-code

Example :

Barcode barcode = BarcodeFactory.createCode128(id); barcode.setDrawingText(false); BarcodeImageHandler.writePNG(barcode, new FileOutputStream(new File(file Name))); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.