- java.lang.Object
-
- com.itextpdf.text.pdf.Barcode
-
- Direct Known Subclasses:
Barcode128,Barcode39,BarcodeCodabar,BarcodeEAN,BarcodeEANSUPP,BarcodeInter25,BarcodePostnet
public abstract class Barcode extends java.lang.ObjectBase class containing properties and methods common to all barcode types.- Author:
- Paulo Soares (psoares@consiste.pt)
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringaltTextThe alternate text to be used, if present.protected floatbarHeightThe height of the bars.protected floatbaselineIf positive, the text distance under the bars.protected booleanchecksumTextShows the generated checksum in the the text.static intCODABARA type of barcodeprotected java.lang.StringcodeThe code to generate.static intCODE128A type of barcodestatic intCODE128_RAWA type of barcodestatic intCODE128_UCCA type of barcodeprotected intcodeTypeThe code type.static intEAN13A type of barcodestatic intEAN8A type of barcodeprotected booleanextendedGenerates extended barcode 39.protected BaseFontfontThe text font.protected booleangenerateChecksumThe optional checksum generation.protected booleanguardBarsShow the guard bars for barcode EAN.protected floatinkSpreadingThe ink spreading.protected floatnThe bar multiplier for wide bars or the distance between bars for Postnet and Planet.static intPLANETA type of barcodestatic intPOSTNETA type of barcodeprotected floatsizeThe size of the text or the height of the shorter bar in Postnet.protected booleanstartStopTextShow the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.static intSUPP2A type of barcodestatic intSUPP5A type of barcodeprotected inttextAlignmentThe text alignment.static intUPCAA type of barcodestatic intUPCEA type of barcodeprotected floatxThe minimum bar width.
-
Constructor Summary
Constructors Constructor Description Barcode()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.awt.ImagecreateAwtImage(java.awt.Color foreground, java.awt.Color background)Creates ajava.awt.Image.ImagecreateImageWithBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)Creates anImagewith the barcode.PdfTemplatecreateTemplateWithBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)Creates a template with the barcode.java.lang.StringgetAltText()Gets the alternate text.abstract RectanglegetBarcodeSize()Gets the maximum area that the barcode and the text, if any, will occupy.floatgetBarHeight()Gets the height of the bars.floatgetBaseline()Gets the text baseline.java.lang.StringgetCode()Gets the code to generate.intgetCodeType()Gets the code type.BaseFontgetFont()Gets the text font.floatgetInkSpreading()Gets the amount of ink spreading.floatgetN()Gets the bar multiplier for wide bars.floatgetSize()Gets the size of the text.intgetTextAlignment()Gets the text alignment.floatgetX()Gets the minimum bar width.booleanisChecksumText()Gets the property to show the generated checksum in the the text.booleanisExtended()Gets the property to generate extended barcode 39.booleanisGenerateChecksum()Gets the optional checksum generation.booleanisGuardBars()Gets the property to show the guard bars for barcode EAN.booleanisStartStopText()Sets the property to show the start and stop character '*' in the text for the barcode 39.abstract RectangleplaceBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)Places the barcode in aPdfContentByte.voidsetAltText(java.lang.String altText)Sets the alternate text.voidsetBarHeight(float barHeight)Sets the height of the bars.voidsetBaseline(float baseline)Sets the text baseline.voidsetChecksumText(boolean checksumText)Sets the property to show the generated checksum in the the text.voidsetCode(java.lang.String code)Sets the code to generate.voidsetCodeType(int codeType)Sets the code type.voidsetExtended(boolean extended)Sets the property to generate extended barcode 39.voidsetFont(BaseFont font)Sets the text font.voidsetGenerateChecksum(boolean generateChecksum)Setter for property generateChecksum.voidsetGuardBars(boolean guardBars)Sets the property to show the guard bars for barcode EAN.voidsetInkSpreading(float inkSpreading)Sets the amount of ink spreading.voidsetN(float n)Sets the bar multiplier for wide bars.voidsetSize(float size)Sets the size of the text.voidsetStartStopText(boolean startStopText)Gets the property to show the start and stop character '*' in the text for the barcode 39.voidsetTextAlignment(int textAlignment)Sets the text alignment.voidsetX(float x)Sets the minimum bar width.
-
-
-
Field Detail
-
EAN13
public static final int EAN13
A type of barcode- See Also:
- Constant Field Values
-
EAN8
public static final int EAN8
A type of barcode- See Also:
- Constant Field Values
-
UPCA
public static final int UPCA
A type of barcode- See Also:
- Constant Field Values
-
UPCE
public static final int UPCE
A type of barcode- See Also:
- Constant Field Values
-
SUPP2
public static final int SUPP2
A type of barcode- See Also:
- Constant Field Values
-
SUPP5
public static final int SUPP5
A type of barcode- See Also:
- Constant Field Values
-
POSTNET
public static final int POSTNET
A type of barcode- See Also:
- Constant Field Values
-
PLANET
public static final int PLANET
A type of barcode- See Also:
- Constant Field Values
-
CODE128
public static final int CODE128
A type of barcode- See Also:
- Constant Field Values
-
CODE128_UCC
public static final int CODE128_UCC
A type of barcode- See Also:
- Constant Field Values
-
CODE128_RAW
public static final int CODE128_RAW
A type of barcode- See Also:
- Constant Field Values
-
CODABAR
public static final int CODABAR
A type of barcode- See Also:
- Constant Field Values
-
x
protected float x
The minimum bar width.
-
n
protected float n
The bar multiplier for wide bars or the distance between bars for Postnet and Planet.
-
font
protected BaseFont font
The text font.nullif no text.
-
size
protected float size
The size of the text or the height of the shorter bar in Postnet.
-
baseline
protected float baseline
If positive, the text distance under the bars. If zero or negative, the text distance above the bars.
-
barHeight
protected float barHeight
The height of the bars.
-
textAlignment
protected int textAlignment
The text alignment. Can beElement.ALIGN_LEFT,Element.ALIGN_CENTERorElement.ALIGN_RIGHT.
-
generateChecksum
protected boolean generateChecksum
The optional checksum generation.
-
checksumText
protected boolean checksumText
Shows the generated checksum in the the text.
-
startStopText
protected boolean startStopText
Show the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.
-
extended
protected boolean extended
Generates extended barcode 39.
-
code
protected java.lang.String code
The code to generate.
-
guardBars
protected boolean guardBars
Show the guard bars for barcode EAN.
-
codeType
protected int codeType
The code type.
-
inkSpreading
protected float inkSpreading
The ink spreading.
-
altText
protected java.lang.String altText
The alternate text to be used, if present.
-
-
Method Detail
-
getX
public float getX()
Gets the minimum bar width.- Returns:
- the minimum bar width
-
setX
public void setX(float x)
Sets the minimum bar width.- Parameters:
x- the minimum bar width
-
getN
public float getN()
Gets the bar multiplier for wide bars.- Returns:
- the bar multiplier for wide bars
-
setN
public void setN(float n)
Sets the bar multiplier for wide bars.- Parameters:
n- the bar multiplier for wide bars
-
getFont
public BaseFont getFont()
Gets the text font.nullif no text.- Returns:
- the text font.
nullif no text
-
setFont
public void setFont(BaseFont font)
Sets the text font.- Parameters:
font- the text font. Set tonullto suppress any text
-
getSize
public float getSize()
Gets the size of the text.- Returns:
- the size of the text
-
setSize
public void setSize(float size)
Sets the size of the text.- Parameters:
size- the size of the text
-
getBaseline
public float getBaseline()
Gets the text baseline. If positive, the text distance under the bars. If zero or negative, the text distance above the bars.- Returns:
- the baseline.
-
setBaseline
public void setBaseline(float baseline)
Sets the text baseline. If positive, the text distance under the bars. If zero or negative, the text distance above the bars.- Parameters:
baseline- the baseline.
-
getBarHeight
public float getBarHeight()
Gets the height of the bars.- Returns:
- the height of the bars
-
setBarHeight
public void setBarHeight(float barHeight)
Sets the height of the bars.- Parameters:
barHeight- the height of the bars
-
getTextAlignment
public int getTextAlignment()
Gets the text alignment. Can beElement.ALIGN_LEFT,Element.ALIGN_CENTERorElement.ALIGN_RIGHT.- Returns:
- the text alignment
-
setTextAlignment
public void setTextAlignment(int textAlignment)
Sets the text alignment. Can beElement.ALIGN_LEFT,Element.ALIGN_CENTERorElement.ALIGN_RIGHT.- Parameters:
textAlignment- the text alignment
-
isGenerateChecksum
public boolean isGenerateChecksum()
Gets the optional checksum generation.- Returns:
- the optional checksum generation
-
setGenerateChecksum
public void setGenerateChecksum(boolean generateChecksum)
Setter for property generateChecksum.- Parameters:
generateChecksum- New value of property generateChecksum.
-
isChecksumText
public boolean isChecksumText()
Gets the property to show the generated checksum in the the text.- Returns:
- value of property checksumText
-
setChecksumText
public void setChecksumText(boolean checksumText)
Sets the property to show the generated checksum in the the text.- Parameters:
checksumText- new value of property checksumText
-
isStartStopText
public boolean isStartStopText()
Sets the property to show the start and stop character '*' in the text for the barcode 39.- Returns:
- value of property startStopText
-
setStartStopText
public void setStartStopText(boolean startStopText)
Gets the property to show the start and stop character '*' in the text for the barcode 39.- Parameters:
startStopText- new value of property startStopText
-
isExtended
public boolean isExtended()
Gets the property to generate extended barcode 39.- Returns:
- value of property extended.
-
setExtended
public void setExtended(boolean extended)
Sets the property to generate extended barcode 39.- Parameters:
extended- new value of property extended
-
getCode
public java.lang.String getCode()
Gets the code to generate.- Returns:
- the code to generate
-
setCode
public void setCode(java.lang.String code)
Sets the code to generate.- Parameters:
code- the code to generate
-
isGuardBars
public boolean isGuardBars()
Gets the property to show the guard bars for barcode EAN.- Returns:
- value of property guardBars
-
setGuardBars
public void setGuardBars(boolean guardBars)
Sets the property to show the guard bars for barcode EAN.- Parameters:
guardBars- new value of property guardBars
-
getCodeType
public int getCodeType()
Gets the code type.- Returns:
- the code type
-
setCodeType
public void setCodeType(int codeType)
Sets the code type.- Parameters:
codeType- the code type
-
getBarcodeSize
public abstract Rectangle getBarcodeSize()
Gets the maximum area that the barcode and the text, if any, will occupy. The lower left corner is always (0, 0).- Returns:
- the size the barcode occupies.
-
placeBarcode
public abstract Rectangle placeBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)
Places the barcode in aPdfContentByte. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.The bars and text are written in the following colors:
barColortextColorResult
nullnullbars and text painted with current fill color
barColornullbars and text painted with
barColornulltextColorbars painted with current color
text painted withtextColorbarColortextColorbars painted with
barColor
text painted withtextColor- Parameters:
cb- thePdfContentBytewhere the barcode will be placedbarColor- the color of the bars. It can benulltextColor- the color of the text. It can benull- Returns:
- the dimensions the barcode occupies
-
createTemplateWithBarcode
public PdfTemplate createTemplateWithBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)
Creates a template with the barcode.- Parameters:
cb- thePdfContentByteto create the template. It serves no other usebarColor- the color of the bars. It can benulltextColor- the color of the text. It can benull- Returns:
- the template
- See Also:
placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
-
createImageWithBarcode
public Image createImageWithBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)
Creates anImagewith the barcode.- Parameters:
cb- thePdfContentByteto create theImage. It serves no other usebarColor- the color of the bars. It can benulltextColor- the color of the text. It can benull- Returns:
- the
Image - See Also:
placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
-
createAwtImage
public abstract java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background)Creates ajava.awt.Image. This image only contains the bars without any text.- Parameters:
foreground- the color of the barsbackground- the color of the background- Returns:
- the image
-
getInkSpreading
public float getInkSpreading()
Gets the amount of ink spreading.- Returns:
- the ink spreading
-
setInkSpreading
public void setInkSpreading(float inkSpreading)
Sets the amount of ink spreading. This value will be subtracted to the width of each bar. The actual value will depend on the ink and the printing medium.- Parameters:
inkSpreading- the ink spreading
-
getAltText
public java.lang.String getAltText()
Gets the alternate text.- Returns:
- the alternate text
-
setAltText
public void setAltText(java.lang.String altText)
Sets the alternate text. If present, this text will be used instead of the text derived from the supplied code.- Parameters:
altText- the alternate text
-
-