We are evaluating the BarCode for Java version to create 2D barcodes using the QR format.
We have a requirement to maintain fixed length values for the data encoded in the barcode. Will the BarCode component allow us to fill the data value with spaces in order to maintain the required length?
For example:
value1: DINUMB01 (8 characters)
value2 : SORTCOD (7 characters)
value3 : AIR (7 characters)
value4: RO123456789 (19 characters)
In this example, values 3 and 4 are smaller than the required length for the field. Can we pad the values with spaces and encode the barcode this way? Will the barcode retain the spaces during the encoding?
value3 : AIRxxxx (7 characters; x represents 4 spaces)
value4: RO123456789xxxxxxxx (19 characters; x represents 7 spaces)
The demo we tried appears to remove the spaces during encoding. Please see attached example test barcode.
Those spaces '\u0020' WILL be encoded into the barcode image:
//Create a BarCodeBuilder instance BarCodeBuilder b= new BarCodeBuilder(); //Width of the smallest module of QR b.setXDimension(1); //Symbology set to QR b.setSymbology(b.SYMBOLOGY_QR); Object[] content ={"DINUMB01", "SORTCOD", "AIR", "RO123456789"}; //Fixed length String codetext = String.format("%1$-8s\n%2$-7s\n%3$-7s\n%4$-19s", content); b.setCodeText(codetext);
Thank you very much for your response. We tried using the code you supplied but now receive some junk characters in our barcode.
Here is our sample code:
import com.aspose.barcode.*;
public class BarcodeSample{
public static void main(String args[]){ //Create a BarCodeBuilder instance BarCodeBuilder b= new BarCodeBuilder(); //Width of the smallest module of QR b.setXDimension(1); //Symbology set to QR b.setSymbology(b.SYMBOLOGY_QR); Object[] content ={"DINUMB01", "SORTCOD", "AIR", "RO123456789"}; //Fixed length String codetext = String.format("%1$-8s\n%2$-7s\n%3$-7s\n%4$-19s", content); b.setCodeText(codetext); try { b.save("c:\\testjava.jpg", "jpg");
} catch(Exception ex) { } } }
Is there any other setting we need to apply on the host machine?
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.