High-performance barcode generation library written in Rust. Supports 34+ symbologies with vector output.
Pure Rust implementation with zero external dependencies for core encoding.
Generate SVG and EPS formats for infinite scalability and print quality.
Configure colors, rotation, quiet zones, and output sizes.
Implements ISO/IEC and GS1 specifications for all supported formats.
| Type | Name | Character Set | Usage | Standard |
|---|---|---|---|---|
code128 | Code 128 (Auto) | Full ASCII | Logistics, Tracking | ISO/IEC 15417 |
code128a | Code 128 A | Upper + Control | Industrial | ISO/IEC 15417 |
code128b | Code 128 B | ASCII Printable | Labels | ISO/IEC 15417 |
code128c | Code 128 C | Numeric pairs | High-density | ISO/IEC 15417 |
gs1128 | GS1-128 | AI + Data | Supply Chain | GS1 General Spec |
code39 | Code 39 | A-Z, 0-9, symbols | Industrial | ISO/IEC 16388 |
code93 | Code 93 | Full ASCII | Logistics | โ |
codabar | Codabar | 0-9, - $ : / . + | Libraries, Labs | โ |
ean13 | EAN-13 | 12-13 digits | Retail (Intl) | ISO/IEC 15420 |
ean8 | EAN-8 | 7-8 digits | Small Products | ISO/IEC 15420 |
upca | UPC-A | 11-12 digits | Retail (US) | ISO/IEC 15420 |
upce | UPC-E | 6-8 digits | Small Products | ISO/IEC 15420 |
itf | ITF | Even digits | Warehouse | ISO/IEC 16390 |
itf14 | ITF-14 | 13-14 digits | Shipping | GS1 General Spec |
msi | MSI Plessey | Numeric | Inventory | โ |
isbn | ISBN | 10/13 digits | Books | ISO 2108 |
sscc | SSCC | 17-18 digits | Shipping Units | GS1 General Spec |
upus10 | UPU S10 | 13 chars | International Mail | UPU S10 |
uspsimb | USPS IMb | 20-31 digits | US Mail | USPS |
| Type | Name | Capacity | Usage | Standard |
|---|---|---|---|---|
qrcode | QR Code | ~4,296 chars | Mobile, URLs | ISO/IEC 18004 |
microqr | Micro QR | ~35 chars | Small items | ISO/IEC 18004 |
datamatrix | Data Matrix | ~2,335 chars | Industrial | ISO/IEC 16022 |
pdf417 | PDF417 | ~1,850 chars | ID Cards | ISO/IEC 15438 |
micropdf417 | Micro PDF417 | ~150 chars | Small labels | ISO/IEC 24728 |
aztec | Aztec Code | ~3,832 chars | Tickets | ISO/IEC 24778 |
maxicode | MaxiCode | ~93 chars | UPS Shipping | ISO/IEC 16023 |
gs1qrcode | GS1 QR | ~4,296 chars | Supply Chain | GS1 General Spec |
gs1datamatrix | GS1 DataMatrix | ~2,335 chars | Healthcare | GS1 General Spec |
| Type | Name | Digits | Equivalent |
|---|---|---|---|
gtin8 | GTIN-8 | 8 | EAN-8 |
gtin12 | GTIN-12 | 12 | UPC-A |
gtin13 | GTIN-13 | 13 | EAN-13 |
gtin14 | GTIN-14 | 14 | ITF-14 |
| Function | Description | Returns |
|---|---|---|
create_encoder(format) | Create encoder by name | Option<Box<dyn Encoder>> |
supported_formats() | List all supported formats | Vec<&str> |
render_svg_configured(matrix, config, type) | Render to SVG | String |
render_eps(matrix, config, type) | Render to EPS | String |
pub trait Encoder {
fn encode(&self, contents: &str) -> Result<BitMatrix, BarcodeError>;
fn barcode_type(&self) -> BarcodeType;
fn format_name(&self) -> &'static str;
}
| Field | Type | Default | Description |
|---|---|---|---|
format | OutputFormat | SVG | SVG, PNG, EPS |
fg_color | Color | #000000 | Foreground color |
bg_color | Option<Color> | None | Background (None = transparent) |
rotation | Rotation | R0 | R0, R90, R180, R270 |
quiet_zone | QuietZone | Modules(0) | Margin around barcode |
size | OutputSize | ModulePixels(4) | Output dimensions |
| Barcode | EC Level | Shape | Columns | Mode | Quiet Zone |
|---|---|---|---|---|---|
qrcode | M (15%) | โ | โ | Auto | 4 modules |
microqr | M | โ | โ | Auto | 2 modules |
datamatrix | โ | Square | โ | Auto | 1 module |
pdf417 | Level 2 | โ | Auto | โ | 2 modules |
aztec | 23% | โ | โ | Auto | 0 |
maxicode | โ | Hexagonal | โ | 4 | 0 |
code128 | โ | โ | โ | Auto | 10 modules |
itf14 | โ | โ | โ | โ | 10 modules |
// HEX format
Color::hex("#FF0000") // Red
Color::hex("#FF000080") // Red with 50% alpha
// sRGB format (0.0-1.0)
Color::srgb(1.0, 0.0, 0.0) // Red
Color::srgba(1.0, 0.0, 0.0, 0.5) // Red with 50% alpha
// RGB format (0-255)
Color::rgb(255, 0, 0) // Red
// Predefined
Color::BLACK
Color::WHITE
Color::TRANSPARENT
use xbarcode::{create_encoder, render_svg_configured, RenderConfig};
// Create encoder
let encoder = create_encoder("qrcode").unwrap();
// Encode data
let matrix = encoder.encode("Hello, World!").unwrap();
// Render to SVG with defaults
let svg = render_svg_configured(&matrix, &RenderConfig::default_svg(), "qrcode");
use xbarcode::{
create_encoder, render_svg_configured, render_eps,
Color, RenderConfig, Rotation, QuietZone, OutputSize, OutputFormat,
};
let encoder = create_encoder("datamatrix").unwrap();
let matrix = encoder.encode("Product ID: 12345").unwrap();
// Custom render config
let config = RenderConfig {
format: OutputFormat::SVG,
fg_color: Color::hex("#1a1a2e").unwrap(),
bg_color: Some(Color::WHITE),
rotation: Rotation::R90,
quiet_zone: QuietZone::Standard,
size: OutputSize::ModulePixels(8),
};
let svg = render_svg_configured(&matrix, &config, "datamatrix");
let eps = render_eps(&matrix, &config, "datamatrix");
use xbarcode::supported_formats;
for format in supported_formats() {
println!("{}", format);
}
// Output: qrcode, datamatrix, pdf417, code128, ean13, ...
QR Code and Micro QR Code bar code symbology specification.
Data Matrix bar code symbology specification.
PDF417 bar code symbology specification.
Aztec Code bar code symbology specification.
MaxiCode bar code symbology specification.
Code 128 bar code symbology specification.
EAN/UPC bar code symbology specification.
GS1-128, GS1 DataMatrix, GS1 QR, SSCC, and application identifiers.