2017-03-17 19 views
0

我目前正在使用Itext 5.5.4。我需要插入一个FNC1代码分离(37)如何使用I-Text为CODE 128 A插入FNC1符号标识符?

37所含变量单位数量,最多8

+0

iText的5.5.11今天将被释放,其中包含条形码128A一个修正:https://github.com/itext/itextpdf/commit/e20dc76e8862422ff366f83f5486ce795a05c8be –

+0

@AmedeeVanGasse谢谢你的 – PbxMan

回答

1

这个问题似乎与iText的5.5.11来解决。我发布这个例子来展示它是如何完成的。

package sandbox.barcodes; 

import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 

import com.itextpdf.text.Document; 
import com.itextpdf.text.DocumentException; 
import com.itextpdf.text.Image; 
import com.itextpdf.text.pdf.Barcode128; 
import com.itextpdf.text.pdf.PdfContentByte; 
import com.itextpdf.text.pdf.PdfPCell; 
import com.itextpdf.text.pdf.PdfPTable; 
import com.itextpdf.text.pdf.PdfWriter; 

public class BarcodeInTable { 
    public static final String DEST = "/tmp/barcode_in_table.pdf"; 

    public static void main(String[] args) throws IOException, DocumentException { 
     File file = new File(DEST); 
     file.getParentFile().mkdirs(); 
     new BarcodeInTable().createPdf(DEST); 
    } 
    public void createPdf(String dest) throws IOException, DocumentException { 
     Document document = new Document(); 
     PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); 
     document.open(); 

     String withFNC1 = "021930063300597615160221105052013760"; 
     String withoutFNC1 = "02193006330059761516022110505201Ê3760"; 

     PdfContentByte cb = writer.getDirectContent(); 
     PdfPTable table = new PdfPTable(2); 

     table.addCell("Without FNC1"); 
     Barcode128 code128 = new Barcode128(); 
     code128.setCode(withFNC1); 
     code128.setCodeType(Barcode128.CODE128); 
     Image code128Image = code128.createImageWithBarcode(cb, null, null); 
     PdfPCell cell = new PdfPCell(code128Image); 
     table.addCell(cell); 

     table.addCell("With FNC1"); 
     code128 = new Barcode128(); 
     code128.setCode(withoutFNC1); 
     code128.setCodeType(Barcode128.CODE128); 
     code128Image = code128.createImageWithBarcode(cb, null, null); 
     cell = new PdfPCell(code128Image); 
     table.addCell(cell); 
     document.add(table); 

     document.close(); 
    } 

}