forked from Uzi-Granot/PdfFileWriter
-
Notifications
You must be signed in to change notification settings - Fork 1
3.7 Draw Barcodes
OgreTransporter edited this page Mar 2, 2020
·
1 revision
The DrawBarcode
method is an example of drawing two barcodes EAN-13 and Code-128.
// Draw Barcode
private void DrawBarcode()
{
// save graphics state
Contents.SaveGraphicsState();
// draw EAN13 barcode
BarcodeEAN13 Barcode1 = new BarcodeEAN13("1234567890128");
Contents.DrawBarcode(1.3, 7.05, 0.012, 0.75, Barcode1, ArialNormal, 8.0);
// create QRCode barcode
QREncoder QREncoder = new QREncoder();
// set error correction code
QREncoder.ErrorCorrection = ErrorCorrection.M;
// set module size in pixels
QREncoder.ModuleSize = 1;
// set quiet zone in pixels
QREncoder.QuietZone = 4;
// encode your text or byte array
QREncoder.Encode(ArticleLink);
// convert QRCode to black and white image
PdfImage BarcodeImage = new PdfImage(Document);
BarcodeImage.LoadImage(QREncoder);
// draw image (height is the same as width for QRCode)
Contents.DrawImage(BarcodeImage, 6.0, 6.8, 1.2);
// define a web link area coinsiding with the qr code
Page.AddWebLink(6.0, 6.8, 7.2, 8.0, ArticleLink);
// restore graphics sate
Contents.RestoreGraphicsState();
return;
}
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.