itextpdf 条码
*************
相关类与接口
Barcode1D
public abstract class Barcode1D {
public static final int ALIGN_LEFT = 1;
public static final int ALIGN_RIGHT = 2;
public static final int ALIGN_CENTER = 3;
protected final Color DEFAULT_BAR_FOREGROUND_COLOR;
protected final Color DEFAULT_BAR_BACKGROUND_COLOR;
protected PdfDocument document;
protected float x;
protected float n;
protected PdfFont font;
protected float size;
protected float baseline;
protected float barHeight;
protected int textAlignment;
protected boolean generateChecksum;
protected boolean checksumText;
protected boolean startStopText;
protected boolean extended;
protected String code;
protected boolean guardBars;
protected int codeType;
protected float inkSpreading;
protected String altText;
*******
构造方法
protected Barcode1D(PdfDocument document) {
this.DEFAULT_BAR_FOREGROUND_COLOR = Color.BLACK;
this.DEFAULT_BAR_BACKGROUND_COLOR = Color.WHITE;
this.code = "";
this.inkSpreading = 0.0F;
this.document = document;
}
*******
其他方法
public void setN(float n) {
public void setX(float x) {
public void setSize(float size) {
public void setCode(String code) {
public void setFont(PdfFont font) {
public void setCodeType(int codeType) {
public void setAltText(String altText) {
public void setBaseline(float baseline) {
public void setBarHeight(float barHeight) {
public void setExtended(boolean extended) {
public void setGuardBars(boolean guardBars) {
public void setInkSpreading(float inkSpreading) {
public void setTextAlignment(int textAlignment) {
public void setChecksumText(boolean checksumText) {
public void setStartStopText(boolean startStopText) {
public void setGenerateChecksum(boolean generateChecksum) {
public float getN() {
public float getX() {
public float getSize() {
public String getCode() {
public PdfFont getFont() {
public int getCodeType() {
public float getBaseline() {
public String getAltText() {
public float getBarHeight() {
public int getTextAlignment() {
public float getInkSpreading() {
public boolean isExtended() {
public boolean isGuardBars() {
public boolean isChecksumText() {
public boolean isStartStopText() {
public boolean isGenerateChecksum() {
public abstract Image createAwtImage(Color var1, Color var2);
public abstract Rectangle getBarcodeSize();
public abstract Rectangle placeBarcode(PdfCanvas var1, com.itextpdf.kernel.colors.Color var2, com.itextpdf.kernel.colors.Color var3);
public PdfFormXObject createFormXObject(PdfDocument document) {
public PdfFormXObject createFormXObject(com.itextpdf.kernel.colors.Color barColor, com.itextpdf.kernel.colors.Color textColor, PdfDocument document) {
PdfFormXObject xObject = new PdfFormXObject((Rectangle)null);
public void fitWidth(float width) {
protected float getDescender() {
Barcode2D
public abstract class Barcode2D {
protected static final float DEFAULT_MODULE_SIZE = 1.0F;
public Barcode2D() {
}
public abstract Rectangle getBarcodeSize();
public abstract Rectangle placeBarcode(PdfCanvas var1, Color var2);
public PdfFormXObject createFormXObject(PdfDocument document) {
public abstract PdfFormXObject createFormXObject(Color var1, PdfDocument var2);
Barcode128
public class Barcode128 extends Barcode1D {
public static final int CODE128 = 1;
public static final int CODE128_UCC = 2;
public static final int CODE128_RAW = 3;
private static final byte[][] BARS = new byte[][]{{2, 1, 2, 2, 2, 2}, {2, 2, 2, 1, 2, 2}, {2, 2, 2, 2, 2, 1}, {1, 2, 1, 2, 2, 3}, {1, 2, 1, 3, 2, 2}, {1, 3, 1, 2, 2, 2}, {1, 2, 2, 2, 1, 3}, {1, 2, 2, 3, 1, 2}, {1, 3, 2, 2, 1, 2}, {2, 2, 1, 2, 1, 3}, {2, 2, 1, 3, 1, 2}, {2, 3, 1, 2, 1, 2}, {1, 1, 2, 2, 3, 2}, {1, 2, 2, 1, 3, 2}, {1, 2, 2, 2, 3, 1}, {1, 1, 3, 2, 2, 2}, {1, 2, 3, 1, 2, 2}, {1, 2, 3, 2, 2, 1}, {2, 2, 3, 2, 1, 1}, {2, 2, 1, 1, 3, 2}, {2, 2, 1, 2, 3, 1}, {2, 1, 3, 2, 1, 2}, {2, 2, 3, 1, 1, 2}, {3, 1, 2, 1, 3, 1}, {3, 1, 1, 2, 2, 2}, {3, 2, 1, 1, 2, 2}, {3, 2, 1, 2, 2, 1}, {3, 1, 2, 2, 1, 2}, {3, 2, 2, 1, 1, 2}, {3, 2, 2, 2, 1, 1}, {2, 1, 2, 1, 2, 3}, {2, 1, 2, 3, 2, 1}, {2, 3, 2, 1, 2, 1}, {1, 1, 1, 3, 2, 3}, {1, 3, 1, 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, 2, 1, 1}, {2, 1, 2, 1, 4, 1}, {2, 1, 4, 1, 2, 1}, {4, 1, 2, 1, 2, 1}, {1, 1, 1, 1, 4, 3}, {1, 1, 1, 3, 4, 1}, {1, 3, 1, 1, 4, 1}, {1, 1, 4, 1, 1, 3}, {1, 1, 4, 3, 1, 1}, {4, 1, 1, 1, 1, 3}, {4, 1, 1, 3, 1, 1}, {1, 1, 3, 1, 4, 1}, {1, 1, 4, 1, 3, 1}, {3, 1, 1, 1, 4, 1}, {4, 1, 1, 1, 3, 1}, {2, 1, 1, 4, 1, 2}, {2, 1, 1, 2, 1, 4}, {2, 1, 1, 2, 3, 2}};
private static final byte[] BARS_STOP = new byte[]{2, 3, 3, 1, 1, 1, 2};
public static final char CODE_AB_TO_C = 'c';
public static final char CODE_AC_TO_B = 'd';
public static final char CODE_BC_TO_A = 'e';
public static final char FNC1_INDEX = 'f';
public static final char START_A = 'g';
public static final char START_B = 'h';
public static final char START_C = 'i';
public static final char FNC1 = 'Ê';
public static final char DEL = 'Ã';
public static final char FNC3 = 'Ä';
public static final char FNC2 = 'Å';
public static final char SHIFT = 'Æ';
public static final char CODE_C = 'Ç';
public static final char CODE_A = 'È';
public static final char FNC4 = 'È';
public static final char STARTA = 'Ë';
public static final char STARTB = 'Ì';
public static final char STARTC = 'Í';
private static Map<Integer, Integer> ais = new HashMap();
private Barcode128.Barcode128CodeSet codeSet;
********
构造方法
public Barcode128(PdfDocument document) {
public Barcode128(PdfDocument document, PdfFont font) {
********
其他方法
public void setCode(String code) {
public void setCodeSet(Barcode128.Barcode128CodeSet codeSet) {
public static String getRawText(String text, boolean ucc) {
public static String getRawText(String text, boolean ucc, Barcode128.Barcode128CodeSet codeSet) {
public Rectangle getBarcodeSize() {
public Barcode128.Barcode128CodeSet getCodeSet() {
public static byte[] getBarsCode128Raw(String text) {
public static String getHumanReadableUCCEAN(String code) {
public static String removeFNC1(String code) {
public Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor) {
public Image createAwtImage(java.awt.Color foreground, java.awt.Color background) {
private static char getStartSymbol(Barcode128.Barcode128CodeSet codeSet) {
static boolean isNextDigits(String text, int textIndex, int numDigits) {
static String getPackedRawDigits(String text, int textIndex, int numDigits) {
********
内部枚举:Barcode128CodeSet
public static enum Barcode128CodeSet {
A,
B,
C,
AUTO;
private Barcode128CodeSet() {
}
}
}
*************
示例
public class Test2 {
private static final String dest = "./barcode/1.pdf";
public static void fun() throws Exception{
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));
Barcode128 barcode128 = new Barcode128(pdfDocument);
barcode128.setCode("http://www.baidu.com");
barcode128.setCodeType(Barcode128.CODE128);
PdfFormXObject object = barcode128.createFormXObject(ColorConstants.BLACK,ColorConstants.ORANGE,pdfDocument);
float x = 100;
float y = 750;
float width = object.getWidth();
float height = object.getHeight();
PdfCanvas canvas = new PdfCanvas(pdfDocument.addNewPage());
canvas.saveState();
canvas.setFillColor(ColorConstants.WHITE);
canvas.rectangle(x, y, width, height);
canvas.fill();
canvas.restoreState();
canvas.addXObjectAt(object, x, y);
pdfDocument.close();
}
public static void main(String[] args) throws Exception{
fun();
}
}
生成的条码