BarcodeRenderer Class
Provides methods to render a linear barcode as a vector scene or as an SVG document.
public static class BarcodeRendererRemarks
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
| Name | Description |
|---|---|
| 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.csCreates 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
barcodeBarcode- The barcode to render.
optionsBarcodeRenderOptions?- The rendering options, or
nullfor the defaults.
Returns
Scene The scene of the barcode, as large as the bars, their quiet zone and the text.
Exceptions
ArgumentNullExceptionbarcode,BarcodeRenderOptions.DarkPaintorBarcodeTextOptions.Fontsisnull.ArgumentOutOfRangeException- An option is out of range, or the dimensions of the drawing are too large.
ToSvg(Barcode, BarcodeRenderOptions?, SvgRenderOptions?)
BarcodeRenderer.csRenders the barcode as an SVG document.
public static string ToSvg(this Barcode barcode, BarcodeRenderOptions? options = null, SvgRenderOptions? svgOptions = null)Parameters
barcodeBarcode- The barcode to render.
optionsBarcodeRenderOptions?- The rendering options, or
nullfor the defaults. svgOptionsSvgRenderOptions?- The options of the SVG writer, or
nullfor the defaults.
Returns
string The SVG document, without an XML declaration.
Exceptions
ArgumentNullExceptionbarcode,BarcodeRenderOptions.DarkPaintorBarcodeTextOptions.Fontsisnull.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.