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.Barcoder.Api;

// 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)
{
    // Initialize the barcoder library with default options.
    var barcoder = new Barcoder();

    // Create a barcode encoder of the specified type and content.
    var encoder = barcoder.CreateEncoder(BarcodeType.DataMatrix, message);

    // Create an SVG renderer for saving the generated barcode.
    var renderer = barcoder.CreateSvgRenderer();

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

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