BarcodeRenderer Class

Provides methods to render a linear barcode as a vector scene or as an SVG document.

public static class BarcodeRenderer

Remarks

The scene is what every renderer draws: BarcodeRenderer.ToSvg writes it as SVG, Meziantou.Framework.Imaging.Barcodes draws it as an image (PNG, WebP, JPEG...), and Meziantou.Framework.Pdf.VectorGraphics as a PDF.

Methods

NameDescription
CreateScene(Barcode, BarcodeRenderOptions?)Creates the scene of the barcode: the quiet zone, the bars and the human-readable text.
ToSvg(Barcode, BarcodeRenderOptions?, SvgRenderOptions?)Renders the barcode as an SVG document.

CreateScene(Barcode, BarcodeRenderOptions?)

BarcodeRenderer.cs

Creates the scene of the barcode: the quiet zone, the bars and the human-readable text.

public static Scene CreateScene(this Barcode barcode, BarcodeRenderOptions? options = null)

Parameters

barcode Barcode
The barcode to render.
options BarcodeRenderOptions?
The rendering options, or null for the defaults.

Returns

Scene The scene of the barcode, as large as the bars, their quiet zone and the text.

Exceptions

ArgumentNullException
barcode, BarcodeRenderOptions.DarkPaint or BarcodeTextOptions.Fonts is null.
ArgumentOutOfRangeException
An option is out of range, or the dimensions of the drawing are too large.

ToSvg(Barcode, BarcodeRenderOptions?, SvgRenderOptions?)

BarcodeRenderer.cs

Renders the barcode as an SVG document.

public static string ToSvg(this Barcode barcode, BarcodeRenderOptions? options = null, SvgRenderOptions? svgOptions = null)

Parameters

barcode Barcode
The barcode to render.
options BarcodeRenderOptions?
The rendering options, or null for the defaults.
svgOptions SvgRenderOptions?
The options of the SVG writer, or null for the defaults.

Returns

string The SVG document, without an XML declaration.

Exceptions

ArgumentNullException
barcode, BarcodeRenderOptions.DarkPaint or BarcodeTextOptions.Fonts is null.
ArgumentOutOfRangeException
An option is out of range, or the dimensions of the drawing are too large.

Remarks

The text is drawn with the fonts of BarcodeTextOptions.Fonts: set SvgRenderOptions.EmbedFonts so that viewers that do not have them draw the text as it was measured.