-
Notifications
You must be signed in to change notification settings - Fork 1
2.6 QR Code Support
The PDF File Writer library provides support for QR Code. It is based on article QR Code Encoder and Decoder .NET(Framework, Standard, Core) Class Library Written in C#. The program supports three characters sets: numeric, alphanumeric and eight-bit byte. The program does not support Kanji characters. The program will scan the data string input and selects the most effective character set. If your data can be divided into segments with just digits or just alphanumeric characters you can create a QR Code object with array of data strings.
Adding QRCode barcode to your PDF document must follow the steps below.
- Create
QREncoder
object. - Set encoding options. All encoding options have default values.
- Encode a data string or a data bytes array.
- Create
PdfImage
. - Draw the barcode image with
PdfContent.DrawImage
QR Code example
// create QRCode barcode
QREncoder QREncoder = new QREncoder();
// set error correction code (default is M)
QREncoder.ErrorCorrection = ErrorCorrection.M;
// set module size in pixels (default is 2)
QREncoder.ModuleSize = 1;
// set quiet zone in pixels (default is 8)
QREncoder.QuietZone = 4;
// ECI Assignment Value (default is -1 not used)
// The ECI value is a number in the range of 0 to 999999.
// or -1 if it is not used
Encoder.ECIAssignValue = -1;
// encode your text or byte array
QREncoder.Encode(ArticleLink);
// convert QRCode to PdfImage in black and white
PdfImage BarcodeImage = new PdfImage(Document, QREncoder);
// draw image (height is the same as width for QRCode)
Contents.DrawImage(BarcodeImage, 6.0, 6.8, 1.2);
For coding examples please review 3.7 Draw Barcodes, ArticleExample.cs and OtherExample.cs source code.
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.