Package com.lowagie.text.pdf
Class Barcode
java.lang.Object
com.lowagie.text.pdf.Barcode
- Direct Known Subclasses:
Barcode128
,Barcode39
,BarcodeCodabar
,BarcodeEAN
,BarcodeEANSUPP
,BarcodeInter25
,BarcodePostnet
Base class containing properties and methods common to all barcode types.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The alternate text to be used, if present.protected float
The height of the bars.protected float
If positive, the text distance under the bars.protected boolean
Shows the generated checksum in the the text.static final int
A type of barcodeprotected String
The code to generate.static final int
A type of barcodestatic final int
A type of barcodestatic final int
A type of barcodeprotected int
The code type.static final int
A type of barcodestatic final int
A type of barcodeprotected boolean
Generates extended barcode 39.protected BaseFont
The text font.protected boolean
The optional checksum generation.protected boolean
Show the guard bars for barcode EAN.protected float
The ink spreading.protected float
The bar multiplier for wide bars or the distance between bars for Postnet and Planet.static final int
A type of barcodestatic final int
A type of barcodeprotected float
The size of the text or the height of the shorter bar in Postnet.protected boolean
Show the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar.static final int
A type of barcodestatic final int
A type of barcodeprotected int
The text alignment.static final int
A type of barcodestatic final int
A type of barcodeprotected float
The minimum bar width. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Image
createAwtImage
(Color foreground, Color background) Creates ajava.awt.Image
.createImageWithBarcode
(PdfContentByte cb, Color barColor, Color textColor) Creates anImage
with the barcode.createTemplateWithBarcode
(PdfContentByte cb, Color barColor, Color textColor) Creates a template with the barcode.Gets the alternate text.abstract Rectangle
Gets the maximum area that the barcode and the text, if any, will occupy.float
Gets the height of the bars.float
Gets the text baseline.getCode()
Gets the code to generate.int
Gets the code type.getFont()
Gets the text font.float
Gets the amount of ink spreading.float
getN()
Gets the bar multiplier for wide bars.float
getSize()
Gets the size of the text.int
Gets the text alignment.float
getX()
Gets the minimum bar width.boolean
Gets the property to show the generated checksum in the the text.boolean
Gets the property to generate extended barcode 39.boolean
Gets the optional checksum generation.boolean
Gets the property to show the guard bars for barcode EAN.boolean
Sets the property to show the start and stop character '*' in the text for the barcode 39.abstract Rectangle
placeBarcode
(PdfContentByte cb, Color barColor, Color textColor) Places the barcode in aPdfContentByte
.void
setAltText
(String altText) Sets the alternate text.void
setBarHeight
(float barHeight) Sets the height of the bars.void
setBaseline
(float baseline) Sets the text baseline.void
setChecksumText
(boolean checksumText) Sets the property to show the generated checksum in the the text.void
Sets the code to generate.void
setCodeType
(int codeType) Sets the code type.void
setExtended
(boolean extended) Sets the property to generate extended barcode 39.void
Sets the text font.void
setGenerateChecksum
(boolean generateChecksum) Setter for property generateChecksum.void
setGuardBars
(boolean guardBars) Sets the property to show the guard bars for barcode EAN.void
setInkSpreading
(float inkSpreading) Sets the amount of ink spreading.void
setN
(float n) Sets the bar multiplier for wide bars.void
setSize
(float size) Sets the size of the text.void
setStartStopText
(boolean startStopText) Gets the property to show the start and stop character '*' in the text for the barcode 39.void
setTextAlignment
(int textAlignment) Sets the text alignment.void
setX
(float x) Sets the minimum bar width.
-
Field Details
-
EAN13
public static final int EAN13A type of barcode- See Also:
-
EAN8
public static final int EAN8A type of barcode- See Also:
-
UPCA
public static final int UPCAA type of barcode- See Also:
-
UPCE
public static final int UPCEA type of barcode- See Also:
-
SUPP2
public static final int SUPP2A type of barcode- See Also:
-
SUPP5
public static final int SUPP5A type of barcode- See Also:
-
POSTNET
public static final int POSTNETA type of barcode- See Also:
-
PLANET
public static final int PLANETA type of barcode- See Also:
-
CODE128
public static final int CODE128A type of barcode- See Also:
-
CODE128_UCC
public static final int CODE128_UCCA type of barcode- See Also:
-
CODE128_RAW
public static final int CODE128_RAWA type of barcode- See Also:
-
CODABAR
public static final int CODABARA type of barcode- See Also:
-
x
protected float xThe minimum bar width. -
n
protected float nThe bar multiplier for wide bars or the distance between bars for Postnet and Planet. -
font
The text font.null
if no text. -
size
protected float sizeThe size of the text or the height of the shorter bar in Postnet. -
baseline
protected float baselineIf positive, the text distance under the bars. If zero or negative, the text distance above the bars. -
barHeight
protected float barHeightThe height of the bars. -
textAlignment
protected int textAlignmentThe text alignment. Can beElement.ALIGN_LEFT
,Element.ALIGN_CENTER
orElement.ALIGN_RIGHT
. -
generateChecksum
protected boolean generateChecksumThe optional checksum generation. -
checksumText
protected boolean checksumTextShows the generated checksum in the the text. -
startStopText
protected boolean startStopTextShow the start and stop character '*' in the text for the barcode 39 or 'ABCD' for codabar. -
extended
protected boolean extendedGenerates extended barcode 39. -
code
The code to generate. -
guardBars
protected boolean guardBarsShow the guard bars for barcode EAN. -
codeType
protected int codeTypeThe code type. -
inkSpreading
protected float inkSpreadingThe ink spreading. -
altText
The alternate text to be used, if present.
-
-
Constructor Details
-
Barcode
public Barcode()
-
-
Method Details
-
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
Gets the text font.null
if no text.- Returns:
- the text font.
null
if no text
-
setFont
Sets the text font.- Parameters:
font
- the text font. Set tonull
to 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_CENTER
orElement.ALIGN_RIGHT
.- Returns:
- the text alignment
-
setTextAlignment
public void setTextAlignment(int textAlignment) Sets the text alignment. Can beElement.ALIGN_LEFT
,Element.ALIGN_CENTER
orElement.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
Gets the code to generate.- Returns:
- the code to generate
-
setCode
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
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
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:
table of the colors of the bars and text barColor
textColor
Result
null
null
bars and text painted with current fill color
barColor
null
bars and text painted with
barColor
null
textColor
bars painted with current color
text painted withtextColor
barColor
textColor
bars painted with
barColor
text painted withtextColor
- Parameters:
cb
- thePdfContentByte
where the barcode will be placedbarColor
- the color of the bars. It can benull
textColor
- the color of the text. It can benull
- Returns:
- the dimensions the barcode occupies
-
createTemplateWithBarcode
Creates a template with the barcode.- Parameters:
cb
- thePdfContentByte
to create the template. It serves no other usebarColor
- the color of the bars. It can benull
textColor
- the color of the text. It can benull
- Returns:
- the template
- See Also:
-
createImageWithBarcode
Creates anImage
with the barcode.- Parameters:
cb
- thePdfContentByte
to create theImage
. It serves no other usebarColor
- the color of the bars. It can benull
textColor
- the color of the text. It can benull
- Returns:
- the
Image
- See Also:
-
createAwtImage
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
Gets the alternate text.- Returns:
- the alternate text
-
setAltText
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
-