2017-03-17 37 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(); 
    } 

}