Click or drag to resize

Encode Barcode as PDF

This sample encodes a text message as a two dimensional QR-Code and saves it as a PDF file.

C#
using Opait.Barcode;
using Opait.Barcode.Pdf;

// Encodes a message as QR-Code and saves as a PDF file.
static void EncodePdfBarcode(string message, string fileName)
{
    // Create a barcode of the specified type and content.
    var barcode = Barcode.Create(BarcodeType.QRCode, message);

    // Create a PDF renderer with default parameters.
    var renderer = new BarcodePdfRenderer();

    // Create a new PDF document.
    using (var pdf = new PdfDocument())
    {
        // Add a new page to the document.
        var page = pdf.AddPage();

        // Place the barcode in the middle of the page.
        renderer.RenderBarcode(page, barcode, page.Width / 2 - 100, page.Height / 2 - 100, 200, 200);

        // Save the PDF file.
        pdf.Save(fileName);
    }
}