2D Data Matrix print


Hello there,

I am trying to print 2D Datamatrix according to GS1 standard, I want to know how can I reduce the gap between the 2D barcode and the Caption above. I have attached the image which I generate. So, I want to reduce the gap between the caption and the barcode. Also it would be nice if we could print the caption to the right of the barcode.
Hi Zulf,

Thank you for your inquiry.

Please use the following code snippet to reduce the gap between the caption and the barcode. Furthermore we have already logged a feature request BARCODJAVA-33635 to appear text on the right hand side of the barcode. We will update you once any update is available on this.

CODE:

BarCodeBuilder objBuilder = new BarCodeBuilder(); objBuilder.setSymbologyType(com.aspose.barcode.Symbology.DataMatrix);
objBuilder.setCodeText("1234567890");
objBuilder.setCodeLocation(CodeLocation.None);
objBuilder.getCaptionAbove().setVisible(true);
objBuilder.getCaptionAbove().setText("GTIN: 03453120000011");
objBuilder.getCaptionAbove().setTextAlign(com.aspose.barcode.StringAlignment.Near);

objBuilder.save("test_datamatrix.jpg");


Hi Ikram,

Thank you for your feedback, I tried your code but could not reduce that gap. I have attached the image and also my code which produces this image. Please help.

setLicense();

String dataDir = "Z:\\";
String dst = dataDir + "barcode24.png";

BarCodeBuilder b;
b = new BarCodeBuilder();
b.setSymbologyType(Symbology.GS1DataMatrix);
b.setCodeText("(01)03453120000011(21)11830021212121212133(17)191125(10)ABCD1234");
b.setCodeLocation(CodeLocation.None);
b.getCaptionAbove().setText("GTIN: 03453120000011\nUID:11830021212121212133\nExp: 191125\nLot: ABCD1234");
b.getCaptionAbove().setTextAlign(StringAlignment.Near);
b.getCaptionAbove().setVisible(true);
b.getCaptionAbove().setFont(new java.awt.Font("Arial", Font.PLAIN, 10));

b.getCaptionAbove().setSpace(0);

b.getMargins().setTop(0f);
b.getMargins().setRight(24.5f);
b.getMargins().setLeft(0.5f);
b.setResolution(new Resolution(100, 100, ResolutionMode.Printer));

Hi Zulf,

Thank you for writing us back along with sample image and code.

Please use the following code snippet to generate the barcode with reduced gap between barcode and caption. Sample barcode image generated using the code snippet is attached for your reference.

Furthermore please visit the online documentation link for details regarding Caption class.

BarCodeBuilder objBuilder = new BarCodeBuilder();
objBuilder.setSymbologyType(com.aspose.barcode.Symbology.GS1DataMatrix);
objBuilder.setCodeLocation(CodeLocation.None);
objBuilder.setCodeText("(01)09501101020917(17)190508(10)ABCD1234(410)9501101020917");
//Caption objC = new Caption(“GTIN: 03453120000011”);
Caption objC = new Caption(“GTIN: 03453120000011”,
true,
com.aspose.barcode.StringAlignment.Near,
0,
new java.awt.Color(10),
new java.awt.Font(“Arial”, java.awt.Font.PLAIN, 10)
);

objBuilder.setCaptionAbove(objC);
objBuilder.getMargins().setTop(0f);
objBuilder.getMargins().setRight(24.5f);
objBuilder.getMargins().setLeft(0.5f);

objBuilder.setResolution(new com.aspose.barcode.Resolution(100, 100, com.aspose.barcode.ResolutionMode.Printer));

objBuilder.save(“createBarcode_1.jpg”, ImageFormat.getJpeg());

Hi Ikram,

This code made no difference to what I had. Try to test with this String and you will get that issue which I am facing. It is that \n thingy that is creating the gap. So, try this Cation string.

Caption objC = new Caption("GTIN: 03453120000011\nUID: 11830021212121212133\nExp: 191125\nLot: ABCD1234", true,
com.aspose.barcode.StringAlignment.Near, 0, new java.awt.Color(10),
new java.awt.Font("Arial", java.awt.Font.PLAIN, 10));


Regards
Zulf
Hi Zulf,

Thank you for your inquiry.

The issue that you are facing is due to the number of characters in a single line and available space in the barcode image. In fact it is not an issue. It is the behavior of API to accommodate the characters under the given settings. If you increase the barcode image right margin to 31.5f then string UID: 11830021212121212133 having 25 characters will be accommodated easily without disturbing other settings related to barcode image. Following is the line of code that will work. The resultant barcode image has also been attached for your kind reference.

objBuilder.getMargins().setRight(31.5f);