AspPDF contains the ability to generate printable, scannable barcodes.
12.1.1 Using Barcodes
Barcodes are provided by the DrawBarcode method of the PdfCanvas object.
This method expects two parameters: a string indicating the data to encode as a
barcode, and a PdfParam object or parameter string providing parameters.
The following code sample prints a UPC-A (Universal Product Code) barcode on a page.
VBScript |
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.CreateDocument
Set Page = Doc.Pages.Add
strParam = "x=72; y=696; height=96; width=144; type=1" 'Barcode type 1 is UPC-A
strData = "04310070524"
Page.Canvas.DrawBarcode strData, strParam
|
C# |
IPdfManager objPDF = new PdfManager();
IPdfDocument objDoc = objPDF.CreateDocument(Missing.Value);
IPdfPage objPage = objDoc.Pages.Add(Missing.Value, Missing.Value, Missing.Value);
String strParams = "x=72; y=696; height=96; width=144; type=1"; //Barcode type 1 is UPC-A
String strData = "04310070524"
objPage.Canvas.DrawBarcode( strData, strParam );
|
Click the links below to run this code sample:
http://localhost/asppdf/manual_12/12_barcode.asp
http://localhost/asppdf/manual_12/12_barcode.aspx
This will produce the following:
Note that AspPDF automatically calculated and added the UPC-A check digit (the 6.)
The DrawBarcode method will validate the data passed to it and throw an error exception if it is invalid for the specified type of barcode.
AspPDF also includes a sample of an HTML form page into which a user can enter data for a barcode. This code is not repeated here due to length. Click the links below to run this sample:
http://localhost/asppdf/manual_12/12_barcode_form.asp
http://localhost/asppdf/manual_12/12_barcode_form.aspx
12.1.2 Required Barcode Parameters
Type - What type of barcode to draw. See below for a list of supported types.
X, Y - X and Y coordinates of the lower-left corner of the barcode.
Width, Height - Width and height of the barcode.
The X, Y, Width, and Height parameters only specify the size of the actual
rectangular bars. Text associated with barcodes may extend slightly outside the
specified area.
12.1.3 Optional Barcode Parameters
Color - Specifies the color of the bars and text. This can be a named color constant
like "red" or a hex RGB value. Defaults to black.
BgColor - Specifies the color of the spaces between the bars. If not specified, the
spaces will be transparent. This can be useful to make the spaces in the
barcode white if the page background is non-white. Note that very few scanners
can scan barcodes in colors other than standard black and white.
FontSize - Specifies the size of the font used. This is not used for
certain barcode types like UPC which prescribe all font sizes. This is a maximum
limit on font size. AspPDF will shrink the font as necessary to make the text
fit within the width of a particular barcode type.
BarWeight - Certain barcode types do not prescribe a constant width ratio between "thin" and "wide" bars,
but allow this ratio to be specified. Using this parameter may improve the scannability of these barcode
types with various scanners. Defaults to 2, meaning "wide" bars are twice as wide as "thin" bars.
DrawText - Some barcode types (such as UPC) usually include printed human-readable text. Others
(such as Industrial 2/5) do not. This parameter allows you to override the default behavior. Can be set to
True or False.
AddCheck - A few barcode types allow optional calculation and use of a check digit. Boolean parameter.
Compress - Only used by Code 128, see below. Boolean parameter.
Angle - Specifies an angle of counter-clockwise rotation (in degrees) of the barcode around its lower-left corner.
12.1.4 Supported Barcode Types
(Some images shortened vertically for space)
|
1. UPC-A - The most common type of barcode.
Used in retail applications.
Requires 11 or 12 numeric digits; if 11 are given,
AspPDF calculates and adds the 12th digit which is a check digit.
|
 |
2. UPC-E - A shortened form of UPC-A. Requires 8 numeric digits.
|
 |
3. EAN-13 - A superset of UPC-A, with one additional digit. Requires 12 or 13 numeric digits; the 13th is a check digit in the same manner as UPC-A.
|
 |
4. EAN-8 - A shortened form of EAN-13. Requires 7 or 8 numeric digits; the 8th is a check digit.
|
 |
5. UPC-A with supplemental - A UPC-A code, plus either a 2-digit or 5-digit supplemental code.
Requires 14 numeric digits for the 2-digit version and 17 digits for the 5-digit version.
If the 12th character is a space, AspPDF will calculate a check digit for that space and encode it.
|
 |
6. UPC-E with supplemental - Similar to UPC-A with supplemental. Requires 10 or 13 numeric digits.
|
 |
7. EAN-13 with supplemental - Similar to UPC-A with supplemental. Requires 15 or 17 numeric digits.
Calculates a check digit if the 13th character is a space.
|
 |
8. EAN-8 with supplemental - Similar to UPC-A with supplemental. Requires 10 or 13 numeric digits.
Calculates a check digit if the 8th character is a space.
|
 |
9. 2-digit supplemental - The 2-digit supplemental barcode can be drawn by itself without an accompanying main barcode.
|
 |
10. 5-digit supplemental - See previous.
|
None of the UPC or EAN barcode types use the FontSize or BarWeight parameter. All other barcodes do use FontSize, and use BarWeight unless otherwise specified.
|
 |
11. Industrial 2 of 5 - Can encode any quantity of numeric characters. AspPDF adds the start and stop bars.
|
 |
12. Interleave 2 of 5 - Similar to Industrial 2 of 5 with a more compact encoding scheme.
|
 |
13. Interleave 2 of 5 Special - Same as Interleave 2 of 5 but with different spacing. Does not use BarWeight.
|
 |
14. DataLogic 2 of 5 - Similar to Industrial 2 of 5 but with a different compact encoding scheme.
|
 |
15. Plessey - Can encode any quantity of numeric characters. AspPDF adds the start and stop bars. This image illustrates the use of the BarWeight parameter set to 3. Note that the wide bars are much thicker than the thin bars.
|
 |
16. Codabar - Can encode any quantity of these characters:
0123456789-$:/.+
Requires a matched pair of start and stop characters which must be the letters A, B, C, or D. Does not use BarWeight.
|
 |
17. Code 39 - A common encoding scheme for alphabetic text. Can encode numbers, uppercase letters, and these characters:
-. $/+%
AspPDF encodes lowercase characters as uppercase, and adds start and stop bars.
|
 |
18. Code 11 - Can encode any quantity of numeric characters.
|
 |
20. Code 39 Extended - Can encode the entire ASCII set (characters 0 to 127). Can optionally add a check digit with the AddCheck parameter.
|
 |
21. Code 93 - Can encode the entire ASCII set (characters 0 to 127). Does not use BarWeight.
|
 |
22. Code 128 - Can encode the entire ASCII set (characters 0 to 127). Does not use BarWeight.
Must use a check digit via the AddCheck=true parameter.
Automatically selects between Code-128 encoding schemes as necessary.
Implements the Code-C encoding scheme to compactly encode pairs of digits; this is done if the optional parameter Compress is set to True.
|
 |
23. Code 128 Raw - Provides access to advanced features of Code-128 encoding; AspPDF does not do any processing of the data passed to it, except for adding the stop bars and optionally adding the check digit.
You must provide the start code character; in VB or ASP, this would be ChrW(135) for Code A, ChrW(136) for Code B, and so on.
Consult a Code 128 reference for full information on specifications such as function and shift characters.
|
 |
30. US Postal Code - Printed on mail by the US Postal Service. AspPDF calculates and adds a check digit. Does not use BarWeight.
|
 |
31. UK/Canada Postal Code - Printed on mail by the UK and Canada mail services. Does not use BarWeight.
|