[]
        
(Showing Draft Content)

Barcodes in PDF

Apart from text, images, tables, annotations etc, you might need to add barcodes to your PDF documents. Barcodes can be helpful when you create PDF for inventory management, ticketing system, advertising, invoice, shipping labels etc.


GcPdf supports barcodes through GcBarcode class under GrapeCity.Documents.Barcode namespace that belongs to GrapeCity.Documents.Barcode.dll, an independent assembly that exclusively contains barcode related methods and properties. GcBarcode references are available through NuGet package named GrapeCity.Documents.BarCode. Also, note that GrapeCity.Documents.Barcode.dll is not a part of GcPdf and hence, there are no dependencies between GcPdf and GcBarcode. The assembly just adds extension methods to GcGraphics that allow to draw barcodes on any GcGraphics implementation including GcPdfGraphics.


Barcodes in a PDF document

Supported barcode symbologies

GcPdf offers 38 different barcode symbologies (1D and 2D) or code types which are described in the table below. The GcBarCode assembly provides CodeType property which accepts the values from CodeType enum to set the type of barcode to any of these listed barcode types.

Barcode type

Description

Ansi39

ANSI 3 of 9 (Code 39) uses upper case, numbers, - , * $ / + %. This is the default barcode style.

Ansi39x

ANSI Extended 3 of 9 (Extended Code 39) uses the complete ASCII character set.

Bc412

The BC412 barcode was invented by IBM to meet the needs of the semiconductor wafer identification application.

Codabar

Codabar uses A B C D + - : . / and numbers.

Code11

Code11, also known as USD-8, is a high-density barcode symbology developed by Intermec in 1977. It is primarily used to label telecommunication equipments. This symbology is discrete and is able to encode numeric digits through 0-9, dash (-), and start/stop characters.

Code_128_A

Code 128 A uses control characters, numbers, punctuation, and upper case.

Code_128_B

Code 128 B uses punctuation, numbers, upper case, and lower case.

Code_128_C

Code 128 C uses only numbers.

Code_128auto

Code 128 Auto uses the complete ASCII character set. Automatically selects between Code 128 A, B, and C to give the smallest barcode.

Code_2_of_5

Code 2 of 5 uses only numbers.

Code93

Code 93 uses uppercase, % $ * / , + -, and numbers.

Code25intlv

Interleaved 2 of 5 uses only numbers.

Code39

Code 39 uses numbers, % * $ /. , - +, and upper case.

Code39x

Extended Code 39 uses the complete ASCII character set.

Code49

Code 49 is a two-dimensional high-density stacked barcode containing two to eight rows of eight characters each. Each row has a start code and a stop code. Encodes the complete ASCII character set.

Code93x

Extended Code 93 uses the complete ASCII character set.

DataMatrix

Data Matrix is a high density, two-dimensional barcode with square modules arranged in a square or rectangular matrix pattern.

EAN_13

EAN-13 uses only numbers (12 numbers and a check digit). It takes only 12 numbers as a string to calculate a check digit (CheckSum) and add it to the thirteenth position. If there are thirteen numbers, it validates the checksum and throws an error if it is incorrect.

EAN_8

EAN-8 uses only numbers (7 numbers and a check digit).

EAN128FNC1

EAN-128 is an alphanumeric one-dimensional representation of Application Identifier (AI) data for marking containers in the shipping industry.

This type of bar code contains the following sections:

  • Leading quiet zone (blank area)

  • Code 128 start character

  • FNC (function) 1 character which allows scanners to identify this as an EAN-128 barcode

  • Data (AI plus data field)

  • Symbol check character (Start code value plus product of each character position plus value of each character divided by 103. The checksum is the remainder value.)

  • Stop character

  • Trailing quiet zone (blank area)

The AI in the Data section sets the type of the data to follow (i.e. ID, dates, quantity, measurements, etc.). There is a specific data structure for each type of data. This AI is what distinguishes the EAN-128 code from Code 128.

Multiple AIs (along with their data) can be combined into a single bar code.

EAN128FNC1 is a UCC/EAN-128 (EAN128) type barcode that allows you to insert FNC1 character at any place and adjust the bar size, etc., which is not available in UCC/EAN-128.

To insert FNC1 character, set “\n” (for C#), or “vbLf” (for VB) to Text property at runtime.

HIBCCode128

HIBCCode128 is a Health Industry Bar Code 128 implementation.

HIBCCode39

HIBCCode39 is a Health Industry Bar Code 39 implementation.

Iata25

Represents an IATA 2 of 5 barcode.

IntelligentMail

Intelligent Mail, formerly known as the 4-State Customer Barcode, is a 65-bar code used for domestic mail in the U.S.

IntelligentMailPackage

Intelligent Mail Package Barcode.

ISBN

The International Standard Book Number (ISBN) is special commercial book identifier which encodes 9 numeric digits apart from the start number "978", "979".

ISMN

The International Standard Music Number or ISMN (ISO 10957) is a thirteen-character alphanumeric identifier for printed music developed by ISO.

ISSN

The International Standard Serial Number (ISSN) is an eight-digit number used for printed or electronic periodical publications like magazines, etc. This ISSN system was drafted as an International Standard in 1971 and published as ISO 3297 in 1975.

ITF14

ITF14 barcode is the GS1 implementation of an Interleaved 2 of 5 bar code to encode a Global Trade Item Number. It is continuous, self-checking, bidirectionally decodable and it will always encode 14 digits. ITF14 is used on packaging levels of a product in general.

JapanesePostal

This is the barcode used by the Japanese Postal system. Encodes alpha and numeric characters consisting of 20 digits including a 7-digit postal code number, optionally followed by block and house number information. The data to be encoded can include hyphens.

Matrix_2_of_5

Matrix 2 of 5 is a higher density barcode consisting of three black bars and two white bars.

MicroPDF417

MicroPDF417 is two-dimensional, multi-row symbology, derived from PDF417. Micro-PDF417 is designed for applications that need to encode data in a two-dimensional symbol (up to 150 bytes, 250 alphanumeric characters, or 366 numeric digits) with the minimal symbol size.

MicroPDF417 allows you to insert an FNC1 character as a field separator for variable length Application Identifiers (AIs).

To insert FNC1 character, set “\n” (for C#), or “vbLf” (for VB) to Text property at runtime.

MicroQRCode

MicroQRCode is a variant of QR Code 2005. Compared with other regular QR Codes, it has only one position detection pattern which reduces the barcode size so that it can be used to applications where the space for barcode image is severely restricted.

MSI

MSI Code uses only numbers.

Pdf417

Pdf417 is a popular high-density two-dimensional symbology that encodes up to 1108 bytes of information. This barcode consists of a stacked set of smaller barcodes. Encodes the full ASCII character set. It has ten error correction levels and three data compaction modes: Text, Byte, and Numeric. This symbology can encode up to 2725 data characters.

Pharmacode

Pharmacode, also known as Pharmaceutical Binary Code, is a barcode standard, 1D barcode that is used in the pharmaceutical manufacturing industry as a packing control system.

Plessey

MSI barcode, also known as Modified Plessey, is a numeric symbology developed by the MSI Data Corporation, which is used primarily for marking retail shelves for inventory control. Though continuous and self-checking, MSI Plessey provides several module checksum situations.

PostNet

PostNet uses only numbers with a check digit.

PZN

PZN or Pharma-Zentral-Nummer is a barcode standard used in the German pharmaceutical industry for identification of medicines and health-care products.

QRCode

QRCode is a two-dimensional symbology that is capable of handling numeric, alphanumeric and byte data as well as Japanese kanji and kana characters. This symbology can encode up to 7,366 characters.

RM4SCC

Royal Mail RM4SCC uses only letters and numbers (with a check digit). This is the barcode used by the Royal Mail in the United Kingdom.

RSS14

RSS14 is a 14-digit Reduced Space Symbology that encodes Composite Component (CC) extended EAN and UPC information in less space. This version is EAN.UCC item identification for use with omnidirectional point-of-sale scanners.

RSS14Stacked

RSS14Stacked symbology encodes CC extended EAN and UPC information in less space. This version is same as RSS14Truncated, but stacked in two rows for a smaller width.

RSS14Stacked allows you to set Composite Options, where you can select the type of the barcode in the Type drop-down list and the value of the composite barcode in the Value field.

RSS14StackedOmnidirectional

RSS14StackedOmnidirectional symbology encodes CC extended EAN and UPC information in less space. This version is same as RSS14, but stacked in two rows for a smaller width.

RSS14Truncated

RSS14Truncated symbology encodes CC extended EAN and UPC information in less space. This version is a 14-digit EAN.UCC item identification and Indicator digits of zero or one for use on small items not for point-of-sale scanners.

RSSExpanded

RSSExpanded symbology encodes CC extended EAN and UPC information in less space. This version is a 14-digit EAN.UCC item identification and adds AI element strings such as, weight and best-before dates, for use with omnidirectional point-of-sale scanners.

RSSExpanded allows you to insert an FNC1 character as a field separator for variable length Application Identifiers (AIs).

To insert FNC1 character, set “\n” (for C#), or “vbLf” (for VB) to Text property at runtime.

RSSExpandedStacked

RSSExpandedStacked symbology encodes CC extended EAN and UPC information in less space. This version is same as RSSExpanded, but stacked in two rows for a smaller width.

RSSExpandedStacked allows you to insert an FNC1 character as a field separator for variable length Application Identifiers (AIs).

To insert FNC1 character, set “\n” (for C#), or “vbLf” (for VB) to Text property at runtime.

RSSLimited

RSS Limited symbology encodes CC extended EAN and UPC information in less space. This version is a 14-digit EAN.UCC item identification with indicator digits of 0 to 1 in small symbol that is not scanned by point-of-sale scanners.

RSSLimited allows you to set Composite Options, where you can select the type of the barcode in the Type drop-down list and the value of the composite barcode in the Value field.

SSCC18

Serial Shipping Container Code-18 (SSCC-18) Barcode is a type of barcode that can print in the lower 2-inch (or local equivalent) extended area of the Thermal 4" x 8" or 4" x 8¼" (or local equivalent) label.

Telepen

Telepen is a name of a barcode symbology designed in the UK, in 1972, to directly represent the full ASCII character set without using shift characters for code switching, and use only two different widths for bars and spaces.

UCCEAN128

UCC/EAN –128 uses the complete ASCII character Set. This is a special version of Code 128 used in HIBC applications.

UPC_A

UPC-A uses only numbers (11 numbers and a check digit).

UPC_E0

UPC-E0 uses only numbers. Used for zero-compression UPC symbols. For the Caption property, you may enter either a six-digit UPC-E code or a complete 11-digit (includes code type, which must be zero) UPC-A code. If an 11-digit code is entered, the Barcode control will convert it to a six-digit UPC-E code, if possible. If it is not possible to convert from the 11-digit code to the six-digit code, nothing is displayed.

UPC_E1

UPC-E1 uses only numbers. Used typically for shelf labeling in the retail environment. The length of the input string for U.P.C. E1 is six numeric characters.

Barcode properties

The GcBarcode class provides the following common properties for all the barcode types.

Properties

Description

CodeType

Allows you to set the barcode encoding

HorizontalAlignment

Allows you to set the horizontal alignment of a barcode

Options

Gets the BarcodeOptions object to define the additional barcode options

ScaleFactor

Allows you to set the scale factor applied to a barcode image

Text

Allows you to provide the value to be encoded into barcode

TextFormat

Allows you to set the text format to draw the barcode label

VerticalAlignment

Allows you to set the vertical alignment of a barcode

Add Barcodes

To add barcode using GcPdf:

  1. Create an object of GcBarcode class.

  2. Set the required properties of the GcBarcode object.

  3. Draw the barcode using DrawBarcode method provided by the GcPdfGraphics class.

    public void CreatePDF(Stream stream)
       {
          GcPdfDocument doc = new GcPdfDocument();
          var page = doc.NewPage();
          var g = page.Graphics;
          GcBarcode barcode = new GcBarcode()
          {
            CodeType = CodeType.QRCode,
            Text = "QR Code",
          };
          barcode.TextFormat.Font = StandardFonts.Helvetica;
          barcode.Options.TextAlign = TextAlignment.Center;
          barcode.Options.QRCode.ConnectionNumber = 123456;
          g.DrawBarcode(barcode, new RectangleF(72/2, 72/2, 72, 72));
          doc.Save(stream);
        }

For more information about implementation of barcodes in GcPdf, see GcPdf sample browser.