We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Barcode Image with 300DPI

Hi All,

We want to use Aspose.BarCode for generating our 1D and 2D barcodes. What would be the image quality of barcodes generated from this. Is it 96DPI? Can the DPI be increased?

I have used the below code as per the sample provided by aspose, but the DPI is still 96, Please help. I want to generate barcode with 300DPI.

Linear barcode = new Linear();


barcode.setResolution(300);// barcode image resolution in dpi
barcode.setTextFont(new Font(“Arial”, 0, 12));

Hi Deepti,

Thank you for your inquiry and sharing sample.

This is to update you that we have evaluated the code snippet shared by you. It seems that you are using an old version of Aspose.BarCode. It is always recommended to use the latest version. Please download the latest version Aspose.BarCode for Java 17.02 and try the following code snippet at your end.

In case the issue persists, feel free to update us. We will further look into the issue and update you accordingly.


//Instantiate barcode object
BarCodeBuilder bb = new BarCodeBuilder();
//Set the Code text for the barcode
//Set the symbology type to code128
//Create an instance of resolution and apply on the barcode image with customized resolution settings
bb.setResolution(new com.aspose.barcode.Resolution(300f, 300f, com.aspose.barcode.ResolutionMode.Graphics));
String sBarcodeImage = "barcode_out.png";
// Save the image

hi, Thank you for the reply,

With this I am able to get the resolution I need.
Will I be able to resize the barcode to smaller size.

I tried the below code, but getting exception

BarCodeBuilder bbCode128 = new BarCodeBuilder();
bbCode128.setCodeText(“Sample Text 123”);
MarginsF m = new MarginsF(0, 0, 0, 0);
bbCode128.setResolution(new Resolution(300, 300, ResolutionMode.Printer));
bbCode128.save("./images/Code128-300DPI-" + “.jpg”);

I am getting the below exception
class com.aspose.barcode.BarCodeException: Too small image’s size - width: 208.3333px, height: 208.3333px. The generated barcode don’t fit to image. Barcode size - width: 594px, height: 63px.
com.aspose.barcode.j.a(Unknown Source)
com.aspose.barcode.j.a(Unknown Source)
com.aspose.barcode.j.E(Unknown Source)
com.aspose.barcode.BarCodeBuilder.l(Unknown Source)
com.aspose.barcode.BarCodeBuilder.f(Unknown Source)
com.aspose.barcode.BarCodeBuilder.save(Unknown Source)
at com.aspose.barcode.j.a(Unknown Source)
at com.aspose.barcode.j.a(Unknown Source)
at com.aspose.barcode.j.E(Unknown Source)
at com.aspose.barcode.BarCodeBuilder.l(Unknown Source)
at com.aspose.barcode.BarCodeBuilder.f(Unknown Source)
at com.aspose.barcode.BarCodeBuilder.save(Unknown Source)
at com.samples.aspose.only.GenerateAsposeBarcodes.main(GenerateAsposeBarcodes.java:56)

Hi Deepti,

Thank you for writing us back.

This is to update you that Aspose.BarCode provides control over the barcode image size. Please refer to this helping topic: Generate Barcode Using Custom Width Support

The GetOnlyBarCodeImage method allows you to get the exact barcode in Bitmap format. The GetCustomSizeBarCodeImage method allows you to set the size of the whole picture with bar code inside. Please do not truncate the original width, height otherwise you will face recognition failure problems.

Furthermore barcode image height and width can be measured in different units. The default size measurement unit for barcode images is millimeter. For more details on measurement units and how to set, please visit the link Set Size Unit for the Barcode Image.

Barcode size also depends upon the code text length. You will get runtime exception in case the code text does not fit in custom defined height and width. Sample code snippet to generate barcode with custom defined height and width is attached for your reference.

Hope the above information helps. Feel free to contact us in case of any query or comments.


BarCodeBuilder objBuilder = new BarCodeBuilder();

Hi, Thank you for the reply.

1) I am evaluating Aspose.BarCode, an evaluation watermark is appearing for the generated barcode.
The barcode image is divided into two parts, half is watermark and other half is the barcode. (See attached image)

When using the actual library(licensed), will the image size be same as evaluation version size with barcode part occupying the full size or image will be only the barcode part of the image.

2) GetOnlyBarCodeImage is not available in evaluation version, so I am not able to check this.
If we remove margins and setCodeLocation(CodeLocation.None), then will the image size from getBarCodeImage() be same as GetOnlyBarCodeImage().

3) My use case is to put this image into PDF at a particular location and barcode should be of particular size.
I am unable to evaluate this correctly because of the watermark.

4) Is there any minimum image size restriction for the barcode generated?

Hi Deepti,

This is to update you that water mark is due to the evaluation version. You can get temporary license for evaluation purpose. Please visit the link for detail on How to get temporary license.

Once the watermark will disappear, the image size will not be the same. It will reduce to your settings. With the temporary license, you will get access to GetOnlyBarCodeImage method. If you remove margins and set setCodeLocation to None then the image size will be different from getBarCodeImage() to getOnlyBarCodeImage(). Furthermore minimum barcode image size depends upon code text length as updated you in the previous reply. You defiantly will get runtime exception in case the code text does not fit in custom defined height and width.

Hi, Thank you.

We have got the temporary licence. We are further evaluating it.

You defiantly will get runtime exception in case the code text does not fit in custom defined height and width. - For barcode image size I know it depends on the length, but does your API have any method to get the minimum size required for a particular length of data. Is it possible, to find out the minimum height and width required for a particular data length, Say, I know my data is going to be of 10 characters and it is going to be numbers or aphabets or mix of both.
I went through the API but could find out if any method is available.

Also, when I am printing this barcode image in label printer, the barcode lines are not smooth for some images, some lines are wavy, may be again it is dependent on the size, I am not sure.

Another question, aspose-barcode-17.02.jar is compatible with which version of Java… we want to use it with Java 1.5

Hi Deepti,

This is to update you that the feature you are looking for is not available. A feature request has been logged into our system with ID BARCODEJAVA-222. Our product team will further look into it and provide feedback. We will update you with the feedback in this forum thread once available.

Furthermore aspose-barcode-17.02.jar is not compatible to with JAVA 1.5. It is built using 1.7 JDK.

Thank you for logging feature request.

Is there any version of Aspose.BarCode for Java which would be compatible with 1.5
Hi Deepti,

Latest version of Aspose.Barcode for Java is compatible with JAVA 1.6. Support for JAVA versions 1.4 & 1.5 have been stopped since Aspose.Barcode for Java 6.8. Furthermore it is always recommended to use latest version of the APIs as it contains new features and fixes for issues reported by customers. You may consider updating the Java runtime and use our latest versions.

Ok, we are considering upgrading the java Runtime.

I have used getCustomSizeBarCodeImage method and drawn the same barcode value in 4 different sizes. Value of the barcode is 1234.

I have printed it in normal printer and also a label printer.
My concern is, in label printer, the barcode lines are not smooth, the lines are shaky/crooked.
Please zoom and see the image photographs attached.

Below is the code I am using

File licenseFile=new File(“Aspose.BarCode.lic”);
License license = new com.aspose.barcode.License();
license.setLicense(new FileInputStream(licenseFile));
BarCodeBuilder bbCode128 = new BarCodeBuilder();
MarginsF m = new MarginsF(0, 0, 0, 0);//No whitespace around barcode
bbCode128.setResolution(new Resolution(300, 300, ResolutionMode.Printer));
BufferedImage bImage1 = bbCode128.getCustomSizeBarCodeImage(new Dimension(width, height), false);
g.drawImage(bImage1, 0, 0, null);
Hi Deepti,

This is to update you that we have investigated the issue. We are unable to reproduce the issue while initial investigation. The issue has been logged into our system under investigation ticket ID BARCODEJAVA-229. Our product team will further look into it and provide feedback. We will share the feedback with you in this forum thread once available.

In the mean while please share the complete code. This will help us to reproduce the issue at our end.


This is to update you that Aspose.BarCode for Java 17.7 version has been released where the issue has been fixed. Please download this latest version for testing at your end and let us know if we can be of any additional help to you.