-
Notifications
You must be signed in to change notification settings - Fork 1
2.5 Barcode Support
The code below illustrates how to include UPC-A barcode in a PDF document.
// create barcode object
BarcodeEAN13 Barcode = new BarcodeEAN13("123456789010");
// draw the barcode including text under the barcode
Contents.DrawBarcode(PosX, PosY, BarWidth, BarcodeHeight, Barcode, Font, FontSize);
In this case the class is BarcodeEAN13
with 12 digits input string. The result is UPC-A barcode.
The PDF File Writer library includes a base class Barcode
. For each supported barcode one needs a derived class. The class library includes four derived classes: Barcode128
, Barcode39
, BarcodeInterleaved2of5
and BarcodeEAN13
. The BarcodeEAN13
produces EAN-13 barcode if the input string is 13 digits and UPC-A if the input string is 12 digits. Input string with 13 digit and a leading zero is considered UPC-A.
The DrawBarcode
method has a number of overloads. You specify the position of the bottom left corner of the barcode, the width of the narrow bar, the height of the barcode and the derived barcode class. There are optional arguments: justification (left, center, right) color and font to display the text. Quiet zone around the barcode is your responsibility. Optional text is displayed below the barcode. If you select color other than black you should make sure the contrast to the background is significant. Usage examples are given in 3.7 Draw Barcodes, ArticleExample.cs and OtherExample.cs.
If you want to create a derived class for another barcode, use the source code for the three included classes as an example.
This page is a copy from https://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library by Uzi Granot. The article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL). All rights to the texts and source code remain with Uzi Granot.