barcode generated via itext is not being scanned

2019-09-14 16:11发布

问题:

i have successfully generated barcode using itext5. but the problem i am having now is whenever i try to scan generated barcode via xlab scaner model YT-760 it fails to read it.

BarcodeInTable

  import com.itextpdf.text.Document;
  import com.itextpdf.text.DocumentException;
  import com.itextpdf.text.Image;
  import com.itextpdf.text.Phrase;
  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;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;

   public class BarcodeInTable {
public static final String DEST = "D:/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 code = "675-FH-A12";

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


    Barcode128 barcode128 = new Barcode128();
    barcode128.setFont(null);
    barcode128.setCode(code);
    barcode128.setCodeType(Barcode128.CODE128);
    Image barcode128Image = barcode128.createImageWithBarcode(cb,null,null);
    PdfPCell cell = new PdfPCell();
    cell.addElement(new Phrase("PO"+code));
    cell.addElement(barcode128Image);
    table.addCell(cell);


    document.add(table);

    document.close();
    }

   }

do i have to write codes to make printed barcode to make it readable ? or simply printing generated barcode will be scannable?

p.s i am printing barcode with sato SA408 printer to print barcode. even printing on plain paper and trying to scan won't work.

标签: java pdf itext