Skip to content

2.6 QR Code Support

OgreTransporter edited this page Mar 2, 2020 · 1 revision

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.

Clone this wiki locally