Click or drag to resize

Encode barcode as SVG

This sample encodes a text message as a two dimensional DataMatrix and saves it in SVG format.

C#
using Opait.Barcode;

// This sample creates a DataMatrix barcode and saves it as a standalone SVG file.
// Scalable Vector Graphics files are in XML format and can be viewed by most browsers.
static void EncodeSvgBarcode(string message, string fileName)
{
    // Create a barcode of the specified type and content.
    var barcode = Barcode.Create(BarcodeType.DataMatrix, message);

    // Create an SVG renderer with default parameters.
    var renderer = new BarcodeSvgRenderer();

    // Render to SVG format of 400x400 pixels.
    var content = renderer.RenderBarcode(barcode, 400, 400, true);

    // Save to a file as a standalone SVG image.
    System.IO.File.WriteAllText(fileName, content);
}