Example_21

Using QR code 2D barcodes with Low, Medium, High and Very High error correction levels.

Example_21.pdf — the PDF this example creates.

/*
 * Example_21.cs
 *
 * Copyright (c) 2026 PDFjet Software
 * Licensed under the MIT License. See LICENSE file in the project root.
 */
using System;
using System.IO;
using System.Diagnostics;
using PDFjet.NET;

/**
 * Example_21.cs
 */
public class Example_21 {
    public Example_21() {
        PDF pdf = new PDF(new BufferedStream(
                new FileStream("Example_21.pdf", FileMode.Create)));

        Font f1 = new Font(pdf, IBMPlexSans.Regular);

        Page page = new Page(pdf, Letter.PORTRAIT);

        TextLine text = new TextLine(f1,
                "QR codes encoded with Low, Medium, High and Very High error correction level");
        text.SetLocation(100.0f, 30.0f);
        text.DrawOn(page);

        // Please note:
        // The higher the error correction level - the shorter the string that you can encode.
        QRCode qr = new QRCode(
                "https://kazuhikoarase.github.io/qrcode-generator/js/demo",
                ErrorCorrectionLevel.L);   // Low
        qr.SetModuleLength(3f);
        qr.SetLocation(100f, 100f);
        // qr.SetModuleColor(Color.blue);
        qr.DrawOn(page);

        qr = new QRCode(
                "https://github.com/kazuhikoarase/qrcode-generator",
                ErrorCorrectionLevel.M);   // Medium
        qr.SetLocation(400f, 100f);
        qr.SetModuleLength(3f);
        qr.DrawOn(page);

        qr = new QRCode(
                "https://github.com/kazuhikoarase/jaconv",
                ErrorCorrectionLevel.Q);   // High
        qr.SetLocation(100f, 400f);
        qr.SetModuleLength(3f);
        qr.DrawOn(page);

        qr = new QRCode(
                "https://github.com/kazuhikoarase",
                ErrorCorrectionLevel.H);   // Very High
        qr.SetLocation(400f, 400f);
        qr.SetModuleLength(3f);
        qr.DrawOn(page);

        pdf.Complete();
    }

    public static void Main(String[] args) {
        Stopwatch sw = Stopwatch.StartNew();
        long time0 = sw.ElapsedMilliseconds;
        new Example_21();
        long time1 = sw.ElapsedMilliseconds;
        sw.Stop();
        Console.WriteLine($"Example_21 => {time1 - time0,4} ms");
    }
}   // End of Example_21.cs

©2026 PDFjet Software.