|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.BarCode
public class BarCode
This class allows the creation of various bar code symbols. Simply call
the appropriate method to create your BarCode then draw the result of
getCanvas()
onto a page:
BarCode code = BarCode.newCode128("Code 128 Test"); PDFCanvas canvas = code.getCanvas(); page.drawCanvas(canvas, x, y, x+canvas.getWidth(), y+canvas.getHeight());
Field Summary | |
---|---|
static char |
DATAMATRIX_LATCH_ANSIX12
Represents the DataMatrix "Latch to ANSI X.12" character. |
static char |
DATAMATRIX_LATCH_ASCII
Represents the DataMatrix "Latch to ASCII" character. |
static char |
DATAMATRIX_LATCH_BASE256
Represents the DataMatrix "Latch to Base256" character. |
static char |
DATAMATRIX_LATCH_C40
Represents the DataMatrix "Latch to C40" character. |
static char |
DATAMATRIX_LATCH_EDIFACT
Represents the DataMatrix "Latch to EDIFACT" character. |
static char |
DATAMATRIX_LATCH_TEXT
Represents the DataMatrix "Latch to Text" character. |
static char |
FNC1
Represents the FNC1 character, used in a number of barcodes |
static char |
FNC2
Represents the FNC1 character, used in a number of barcodes |
static char |
FNC3
Represents the FNC1 character, used in a number of barcodes |
static char |
FNC4
Represents the FNC1 character, used in a number of barcodes |
static char |
MAXICODE_GS
Represents the MaxiCode "Group Seperator" characters (U+001D). |
static char |
MAXICODE_LATCHA
Represents the MaxiCode "LATCH-A" control character. |
static char |
MAXICODE_LATCHB
Represents the MaxiCode "LATCH-B" control character. |
static char |
MAXICODE_LOCK
Represents the MaxiCode "LOCK-A", "LOCK-B" and "LOCK-C" control characters |
static char |
MAXICODE_RS
Represents the MaxiCode "Record Seperator" characters (U+001E). |
static char |
MAXICODE_SHIFTA
Represents the MaxiCode "SHIFT-A" control character. |
static char |
MAXICODE_SHIFTB
Represents the MaxiCode "SHIFT-B" control character. |
static char |
MAXICODE_SHIFTC
Represents the MaxiCode "SHIFT-C" control character. |
static char |
MAXICODE_SHIFTD
Represents the MaxiCode "SHIFT-D" control character. |
static char |
MAXICODE_SHIFTE
Represents the MaxiCode "SHIFT-E" control character. |
static char |
MAXICODE_THREESHIFTA
Represents the MaxiCode "3 SHIFT-A" control character. |
static char |
MAXICODE_TWOSHIFTA
Represents the MaxiCode "2 SHIFT-A" control character. |
Method Summary | |
---|---|
BufferedImage |
getBufferedImage(double scale,
Paint background)
Create the BarCode as a BufferedImage . |
PDFCanvas |
getCanvas()
Return a new PDFCanvas containing the barcode. |
float |
getHeight()
Return the height of the symbol. |
float |
getMinimumHeight()
Return the recommended minimum height for this symbol. |
float |
getWidth()
Return the width of the symbol. |
static BarCode |
newAztecCode(String data)
Create a new Aztec code representing the specified String. |
static BarCode |
newCodabar(String value,
float xunit)
Create a new Codabar BarCode. |
static BarCode |
newCode128(String value)
Create a new Code-128 BarCode with an X-unit of 1pt (0.353mm) |
static BarCode |
newCode128(String value,
double xunit)
Create a new Code-128 BarCode. |
static BarCode |
newCode39(String value,
boolean checksum)
Create a new Code 3 of 9 code with an X-unit of 1 and a thick/thin bar ratio of 2.8. |
static BarCode |
newCode39(String value,
boolean checksum,
float xunit,
float ratio)
Create a new Code 3 of 9 code. |
static BarCode |
newCode39Extended(String value,
boolean checksum)
Create a new Extended Code 3 of 9 ("Code 39+") code with an X-unit of 1pt (0.353mm) and a thick/thin bar ratio of 2.8 This algorithm uses the same symbology as Code 3 of 9 but can display all ASCII characters. |
static BarCode |
newCode39Extended(String value,
boolean checksum,
float xunit,
float ratio)
Create a new Extended Code 3 of 9 ("Code 39+") code. |
static BarCode |
newCode93(String value,
float xunit)
Create a new Code 93 code. |
static BarCode |
newDataMatrixCode(byte[] data,
int rows,
int cols)
Create a new Data Matrix code representing binary data. |
static BarCode |
newDataMatrixCode(String data)
Create a new Data Matrix code. |
static BarCode |
newDataMatrixCode(String data,
int rows,
int cols)
Create a new Data Matrix code of the specified dimensions. |
static BarCode |
newDataMatrixCode(String data,
int rows,
int cols,
char encoder)
Create a new Data Matrix code using the specified dimensions and encoder. |
static BarCode |
newDeutschePostCode(String value)
Create a new DeutschePost Interleaved 2 of 5 code. |
static BarCode |
newDeutschePostIdentcode(int dist,
int customer,
int mailing)
Create a new DeutschePost "IdentCode", a variation on Interleaved 2 of 5 with a (4,9) weighted modulo 10 checkdigit. |
static BarCode |
newDeutschePostLeitcode(int pz,
int street,
int number,
int product)
Create a new DeutschePost "LeitCode", a variation on Interleaved 2 of 5 with a (4,9) weighted modulo 10 checkdigit. |
static BarCode |
newEAN13(String value)
Create a new GS1 EAN-13 code at a scale of 80%, giving a symbol an inch wide. |
static BarCode |
newEAN13(String value,
double scale)
Create a new GS1 EAN-13 code. |
static BarCode |
newEAN8(String value)
Create a new GS1 EAN-8 code at a scale of 80%, giving a symbol 3/5th of an inch wide. |
static BarCode |
newEAN8(String value,
double scale)
Create a new GS1 EAN-8 code at the specified scale. |
static BarCode |
newIntelligentMail(String value)
Create a new "Intelligent Mail" BarCode, a 4-state barcode used by the USPS and designed to replace PostNet . |
static BarCode |
newInterleaved25(String value,
boolean checksum)
Create a new Interleaved 2 of 5 BarCode with an X-unit of 1pt (0.353mm) and a thick/thin ratio of 2.8. |
static BarCode |
newInterleaved25(String value,
boolean checksum,
float xunit,
float ratio)
Create a new Interleaved 2 of 5 BarCode. |
static BarCode |
newMaxiCode(int service,
String postcode,
int country,
String address)
Create a new MaxiCode representing an address. |
static BarCode |
newMaxiCode(int service,
String postcode,
String country,
String address)
Create a new MaxiCode representing an address. |
static BarCode |
newMaxiCode(String value,
boolean eec)
Create a new MaxiCode representing an address with the specified message. |
static BarCode |
newPDF417(byte[] value,
float xunit,
int securitylevel,
int columns)
Create a new PDF417 BarCode from binary data. |
static BarCode |
newPDF417(String value)
Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437. |
static BarCode |
newPDF417(String value,
float xunit,
int securitylevel,
int columns)
Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437. |
static BarCode |
newPostnet(String value)
Create a new PostNet code, a numeric barcode used by the United States Postal Service. |
static BarCode |
newQRCode(byte[] value,
double modulesize,
int ecc,
int version)
Create a new QR-Code which encodes a series of raw bytes. |
static BarCode |
newQRCode(String value,
double modulesize,
int ecc,
int version)
Create a new QR-Code, a two-dimensional algorithm as defined in ISO/IEC 18004:2006(E) but originally developed by Denso corporation. |
static BarCode |
newQRCode(String value,
String encoding,
double modulesize,
int ecc,
int version)
Create a new QR-Code which encodes a String in a specified encoding. |
static BarCode |
newRM4SCC(String value)
Create a new Royal Mail 4-state Customer Code, an algorithm used by the Royal Mail in the UK. |
void |
setColor(Paint color)
Set the color of the BarCode. |
void |
setHeight(float height)
Set the height of this symbol. |
void |
setInkBleed(double x,
double y)
Set the ink bleed amount - the number of points the bars are expected to expand in a horizontal and vertical direction due to ink bleed or other quirks of the printing process. |
void |
setShowText(boolean show)
Request that a human-readable version of the barcode value is displayed below the code. |
void |
setWidth(float width)
Set the width of this symbol. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char MAXICODE_SHIFTA
public static final char MAXICODE_SHIFTB
public static final char MAXICODE_SHIFTC
public static final char MAXICODE_SHIFTD
public static final char MAXICODE_SHIFTE
public static final char MAXICODE_TWOSHIFTA
public static final char MAXICODE_THREESHIFTA
public static final char MAXICODE_LATCHA
public static final char MAXICODE_LATCHB
public static final char MAXICODE_LOCK
public static final char MAXICODE_GS
public static final char MAXICODE_RS
public static final char DATAMATRIX_LATCH_BASE256
public static final char DATAMATRIX_LATCH_C40
public static final char DATAMATRIX_LATCH_ANSIX12
public static final char DATAMATRIX_LATCH_TEXT
public static final char DATAMATRIX_LATCH_EDIFACT
public static final char DATAMATRIX_LATCH_ASCII
public static final char FNC1
public static final char FNC2
public static final char FNC3
public static final char FNC4
Method Detail |
---|
public static BarCode newInterleaved25(String value, boolean checksum)
value
- the value of the BarCodechecksum
- whether to apply a check digit using the standard (1,3) weighted modulo 10 algorithmpublic static BarCode newInterleaved25(String value, boolean checksum, float xunit, float ratio)
value
- the value of the BarCodechecksum
- whether to apply a check digit using the standard (1,3) weighted modulo 10 algorithmxunit
- the size of the X-Dimension of the barcode, in points - typically about 1ratio
- the ratio of thick-bar width to thin-bar width - typically between 2 and 3public static BarCode newDeutschePostLeitcode(int pz, int street, int number, int product)
pz
- the postal zone (5 digits)street
- the street number (3 digits)number
- the house number (3 digits)product
- the product number (2 digits)public static BarCode newDeutschePostIdentcode(int dist, int customer, int mailing)
dist
- the distribution center code (2 digits)customer
- the customer number (3 digits)mailing
- the mailing number (6 digits)public static BarCode newDeutschePostCode(String value)
value
- the value of the BarCodepublic static BarCode newCode39(String value, boolean checksum)
value
- the value of the BarCodechecksum
- whether to apply the standard Code 3 of 9 checksum algorithmpublic static BarCode newCode39(String value, boolean checksum, float xunit, float ratio)
value
- the value of the BarCodechecksum
- whether to apply the standard Code 3 of 9 checksum algorithmxunit
- the size of the X-Dimension of the barcode, in points - typically about 1ratio
- the ratio of thick-bar width to thin-bar width - typically between 2 and 3public static BarCode newCode39Extended(String value, boolean checksum)
value
- the value of the BarCodechecksum
- whether to apply the standard Code 3 of 9 checksum algorithmpublic static BarCode newCode39Extended(String value, boolean checksum, float xunit, float ratio)
value
- the value of the BarCodechecksum
- whether to apply the standard Code 3 of 9 checksum algorithmxunit
- the size of the X-Dimension of the barcode, in points - typically about 1ratio
- the ratio of thick-bar width to thin-bar width - typically between 2 and 3public static BarCode newCode93(String value, float xunit)
value
- the value of the BarCodexunit
- the size of the X-Dimension of the barcode, in points - typically about 1public static BarCode newEAN13(String value)
Create a new GS1 EAN-13 code at a scale of 80%, giving a symbol an inch wide. An EAN-13 code represents a 13 digit number - broadly speaking, the first 7 digits are the country and manufacturer code, the next 5 digits are the product code, and the final digit the checksum. The 12 digit UPC-A barcodes as used in the USA are just EAN-13 codes with a leading "0".
If the value supplied is greater than 13 digits, a supplemental code will be included which may be 2 or 5 digits long
value
- the value of the BarCode - 12, 13, 14, 15, 17 or 18 digits (if 12, 14 or 17 the check digit will be appended)public static BarCode newEAN13(String value, double scale)
Create a new GS1 EAN-13 code. An EAN-13 code represents a 13 digit number - broadly speaking, the first 7 digits are the country and manufacturer code, the next 5 digits are the product code, and the final digit the checksum. The 12 digit UPC-A barcodes as used in the USA are just EAN-13 codes with a leading "0".
If the value supplied is greater than 13 digits, a supplemental code will be included which may be 2 or 5 digits long
value
- the value of the BarCode - 12, 13, 14, 15, 17 or 18 digits (if 12, 14 or 17 the check digit will be appended)scale
- the scale of the code - typically from 0.8 to 2, representing 80% to 200% scale. A value of
1 results in an X-dimension of 0.936pt (0.33mm).public static BarCode newEAN8(String value)
Create a new GS1 EAN-8 code at a scale of 80%, giving a symbol 3/5th of an inch wide. An EAN-13 code represents an 8 digit number - the last digit is a check digit. It's essentially a cut-down EAN-13 code.
If the value supplied is greater than 8 digits, a supplemental code will be included which may be 2 or 5 digits long
value
- the value - a 7, 8, 9, 10, 12 or 13 digit number (if 7, 9 or 12 the check digit will be appended automatically)public static BarCode newEAN8(String value, double scale)
Create a new GS1 EAN-8 code at the specified scale.
If the value supplied is greater than 8 digits, a supplemental code will be included which may be 2 or 5 digits long
value
- the value - a 7, 8, 9, 10, 12 or 13 digit number (if 7, 9 or 12 the check digit will be appended automatically)scale
- the scale of the code - typically from 0.8 to 2, representing 80% to 200% scale. A value of
1 results in an X-dimension of 0.936pt (0.33mm).public static BarCode newCodabar(String value, float xunit)
value
- the value of the BarCodexunit
- the size of the X-Dimension of the barcode, in points - typically about 1public static BarCode newCode128(String value)
value
- the value of the BarCodenewCode128(String, double)
public static BarCode newCode128(String value, double xunit)
Create a new Code-128 BarCode. This code can display digits, upper and lower-case letters and most punctuation characters from the U+0000 - U+007E (US-ASCII) range. A checksum is automatically included as part of the barcode.
Code 128 has three "character sets" - A, B or C - which encode different
subsets of characters. At any time during the encoding process, a subset
can be chosen by embedding the characters U+0091
, U+0092
or U+0093
into the String being encoded, to switch to set A, B or C
respectively. If no initial character set is chosen, the most appropriate one will
be used. So, for example, to force a String to be encoded using set A, you
could specify the string \u0092CODEHERE
.
GS1 EAN128 barcodes can also be printed by using U+EFC1
for the FNC1 control character, U+EFC2
for FNC2,
U+EFC3
for FNC3 and U+EFC4
for FNC4.
Note: in previous releases the \n
character was repurposed to mean
FNC1, which caused problems when a literal \n
(valid in Code128 set C)
was required. For clarity the functionality has been removed and since 2.11.12,
U+EFC1
is the only way to specify FNC1.
value
- the value of the BarCodexunit
- The size of the X-Dimension of the barcode in points. GS1-128 codes recommend an X-unit of 1.4pt (0.495mm)public static BarCode newPostnet(String value)
value
- the value of the BarCodepublic static BarCode newRM4SCC(String value)
value
- the value of the BarCodepublic static BarCode newIntelligentMail(String value)
PostNet
.
value
- a String of digits 20, 25, 29 or 31 digits longpublic static BarCode newPDF417(String value)
value
- the value of the BarCodenewPDF417(String, float, int, int)
public static BarCode newPDF417(String value, float xunit, int securitylevel, int columns)
value
- the value of the BarCodexunit
- the X-dimension of the barcode in points - typically around 1securitylevel
- how much error correction to apply: -1 to choose an appropriate level or a value from 0 (none) to 8 (512 bytes of error correction). Recommended values are 2 for up to about 70 characters, 3 for up to about 200, 4 for up to about 400 and 5 for more. Remember setting this too high for large volumes of text may cause the maxiumum number of codewords to be reached, which will cause an exception.columns
- the number of data codeword columns in the code - a value greater than 0 will fix the width of the code and allow only the height to vary, whereas 0 will allow the code to auto-size to fit the available space (recommended).public static BarCode newPDF417(byte[] value, float xunit, int securitylevel, int columns)
value
- the value of the BarCode.xunit
- the X-dimension of the barcode in points - typically around 1securitylevel
- how much error correction to apply: -1 to choose an appropriate level or a value from 0 (none) to 8 (512 bytes of error correction). Recommended values are 2 for up to about 70 characters, 3 for up to about 200, 4 for up to about 400 and 5 for more. Remember setting this too high for large volumes of text may cause the maxiumum number of codewords to be reached, which will cause an exception.columns
- the number of data codeword columns in the code - a value greater than 0 will fix the width of the code and allow only the height to vary, whereas 0 will allow the code to auto-size to fit the available space (recommended).public static BarCode newMaxiCode(String value, boolean eec)
MAXICODE_SHIFTA
, MAXICODE_LATCHB
and
MAXICODE_LOCK
may be inserted directly into the value.
value
- the value of the BarCodeeec
- whether to use Extended Error Correction (mode 5).public static BarCode newMaxiCode(int service, String postcode, int country, String address)
BarCode code = BarCode.newMaxiCode(999, "B1050", 57, "Comité Européean de Normalisation"+BarCode.MAXICODE_GS+ "rue de Stassart 36"+BarCode.MAXICODE_GS+"Bruxelles");
service
- the service level, from 1 to 999postcode
- the postcode of the address, either up to nine numeric digits or up to six alphanumeric digitscountry
- the numeric ISO-3166 country codeaddress
- the address to place in the secondary message. Lines in the address should be separated with the MAXICODE_GS
character.public static BarCode newMaxiCode(int service, String postcode, String country, String address)
newMaxiCode(int, String, int, String)
but the country is be specified as a two-letter ISO-3166 country code. For example, to create a
MaxiCode for a US address:
class="example"> BarCode code = BarCode.newMaxiCode(1, "524032140", "US", "AIM USA"+BarCode.MAXICODE_GS+"634 ALPHA DRIVE"+BarCode.MAXICODE_GS+"PITTSBURGH PA");
service
- the service level, from 1 to 999postcode
- the postcode of the address, either up to nine numeric digits or up to six alphanumeric digitscountry
- the two-letter ISO-3166 country codeaddress
- the address to place in the secondary message. Lines in the address should be separated with the MAXICODE_GS
character.public static BarCode newQRCode(String value, double modulesize, int ecc, int version)
value
- the value of the BarCodemodulesize
- The size of a module in mm. This value depends on the scanning device, but recommended absolute minimum values for 600dpi printing are 0.17, 0.21 or 0.25mm. 0.5mm seems to be fairly typical.ecc
- the level of error correction, from 1 (lowest) to 4 (highest) offering 7%, 15%, 25% and 30% redundancy respectively. If in doubt we recommend 2.version
- the "version" or size of the code - 0 to auto-size, or a value from 1 to 40.public static BarCode newQRCode(byte[] value, double modulesize, int ecc, int version)
value
- the value of the BarCode - up to 2593 bytes.modulesize
- The size of a module in mm. This value depends on the scanning device, but recommended absolute minimum values for 600dpi printing are 0.17, 0.21 or 0.25mm. 0.5mm seems to be fairly typical.ecc
- the level of error correction, from 1 (lowest) to 4 (highest) offering 7%, 15%, 25% and 30% redundancy respectively. If in doubt we recommend 2.version
- the "version" or size of the code - 0 to auto-size, or a value from 1 to 40.newQRCode(String, double, int, int)
public static BarCode newQRCode(String value, String encoding, double modulesize, int ecc, int version)
value
- the value of the BarCodeencoding
- the encoding to use to encode the BarCode bytesmodulesize
- The size of a module in mm. This value depends on the scanning device, but recommended absolute minimum values for 600dpi printing are 0.17, 0.21 or 0.25mm. 0.5mm seems to be fairly typical.ecc
- the level of error correction, from 1 (lowest) to 4 (highest) offering 7%, 15%, 25% and 30% redundancy respectively. If in doubt we recommend 2.version
- the "version" or size of the code - 0 to auto-size, or a value from 1 to 40.newQRCode(String, double, int, int)
public static BarCode newDataMatrixCode(String data)
Create a new Data Matrix code.
Data Matrix is a public domain two-dimensional algorithm which encodes data using
one of several algorithms, and can store up to 2,335 characters.
By default an appropriate size and algorithm is chosen, but for
more control the various Data Matrix Latch
characters can be inserted into the String you're encoding to set the algorithm.
This method will choose an appropriate symbol size for the data. Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.
data
- the value of the BarCodepublic static BarCode newDataMatrixCode(String data, int rows, int cols)
Create a new Data Matrix code of the specified dimensions.
Data Matrix is a public domain two-dimensional algorithm which encodes data using
one of several algorithms, and can store up to 2,335 characters.
By default an appropriate algorithm is chosen, but for
more control the various DataMatrix Latch
characters can be inserted into the String you're encoding to set the algorithm.
The supplied dimensions will be used if possible, but if not the symbol will be sized automatically to accodate the data.
Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.
data
- the value of the BarCoderows
- the number of rows in the barcode, or 0 to auto-sizecols
- the number of rows in the barcode, or 0 to auto-sizepublic static BarCode newDataMatrixCode(byte[] data, int rows, int cols)
Create a new Data Matrix code representing binary data. Data Matrix is a public domain two-dimensional algorithm which encodes data using one of several algorithms, and can store up to 2,335 characters.
This method will choose an appropriate symbol size for the data. Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.
data
- the value of the BarCode, which will be encoded as binary datarows
- the number of rows in the barcode, or 0 to auto-sizecols
- the number of rows in the barcode, or 0 to auto-sizepublic static BarCode newDataMatrixCode(String data, int rows, int cols, char encoder)
Latch
characters.
The dimensions may also be specified, or values of 0 can be used to auto-size
the symbol.
Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.
data
- the value of the BarCoderows
- the number of rows in the barcodecols
- the number of rows in the barcodeencoder
- one of DATAMATRIX_LATCH_BASE256
, DATAMATRIX_LATCH_C40
, DATAMATRIX_LATCH_TEXT
, DATAMATRIX_LATCH_ASCII
, DATAMATRIX_LATCH_ANSIX12
or DATAMATRIX_LATCH_EDIFACT
public static BarCode newAztecCode(String data)
public void setInkBleed(double x, double y)
x
- the number of points to adjust the bar width byy
- the number of poitns to adjust the bar height by.public void setColor(Paint color)
null
uses the default
color, which is black in the GrayScale colorspace
public float getWidth()
getCanvas()
public void setWidth(float width)
IllegalArgumentException
. For other algorithms, this will request the
size of the symbol is set to no larger than the specified width (the actual
width chosen result may be smaller). This method will also increase the height
of the barcode to at least that returned by getMinimumHeight()
width
- the requested width of the symbol in points.public float getMinimumHeight()
public void setShowText(boolean show)
getHeight()
and
getMinimumHeight()
public float getHeight()
setShowText(boolean)
is true, and the returned value will match the
height of the canvas returned by getCanvas()
.
public void setHeight(float height)
getMinimumHeight()
. Not all symbologies can
have their height adjusted, and this method may throw an IllegalArgumentException
if that is the case.
height
- the full height of the canvas to be returned by getCanvas()
, in points.public PDFCanvas getCanvas()
PDFCanvas
containing the barcode. The dimensions will match those returned
by getWidth()
and getHeight()
. Although we suggest drawing it onto the page
at the size it's returned, it is possible to stretch the canvas to suit.
PDFCanvas canvas = barcode.getCanvas(); page.drawCanvas(canvas, x, y, x+canvas.getWidth(), y+canvas.getHeight()):
public BufferedImage getBufferedImage(double scale, Paint background)
Create the BarCode as a BufferedImage
. This is a convenience method,
nothing to do with PDF but as the hard work creating the barcodes was
already done it's an easy addition. For example, here's code to create a BarCode as a PNG:
BarCode barcode = BarCode.newPDF417("Testing"); BufferedImage image = barcode.getBufferedImage(0, Color.white); ImageIO.write(image, "png", new File("barcode.png"));versus the equivalent code in a PDF
BarCode barcode = BarCode.newPDF417("Testing"); PDF pdf = new PDF(); PDFCanvas can = barcode.getCanvas(); PDFPage page = pdf.newPage((int)can.getWidth(), (int)can.getHeight()); page.drawCanvas(can, 0, 0, page.getWidth(), page.getHeight()); pdf.render(new FileOutputStream("barcode.pdf"));
Note without a valid license, the barcode will have "DEMO" written overtop"
scale
- how much to scale the barcode, or zero to auto-size. QR-Codes are measured in millimeters rather than points, so this number should be a factor of 0.70556background
- the color to paint the background of the image - pass
in null
to render to a transparent background.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |