P Nayak
P Nayak

Reputation: 39

The text of a barcode is not the same as the text I used to generate it

I generate a barcode from a piece of text. When I decode the barcode, the text is no longer the same. The position of a colon changed.

i.e.

    Name     : RAMACHANDRA
    Roll No : 1001
    Streem   : MCA

But my requirement is below format

    Name    : RAMACHANDRA
    Roll No : 1001
    Streem  : MCA

This is my code

document.add(new Paragraph("NAME.   :"+" "+"RAMACHANDRA",fontH));                       
document.add(new Paragraph("Roll No :"+" "+"1001",fontH));
document.add(new Paragraph("Streem  :"+" "+"MCA",fontH));
document.add(new Paragraph());

code128.setGenerateChecksum(true);              
code128.setCode("1001");
code128.setSize(8);
code128.setBaseline(10);
code128.setBarHeight(40f);
code128.setN(3);
code128.setX(2f);

document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null));

Upvotes: 0

Views: 115

Answers (1)

Joris Schellekens
Joris Schellekens

Reputation: 9022

Putting the content in a table solves the problem.

Document document = new Document(); 
document.open(); 
final String[][] DATA = {{"NAME",":" +"Ramachandra"},{"RoLL No", ":" +"1001"}}; 
PdfPTable table = new PdfPTable(2); 
table.addCell(DATA[0][0]); 
table.addCell(DATA[0][1]); 
table.addCell(DATA[1][0]); 
table.addCell(DATA[1][1]); 
document.close();

Upvotes: 2

Related Questions