.NET SDK

Printivo .NET SDK

Generate QR codes, render ZPL labels, and create barcodes in C# with strongly-typed models, async/await support, and built-in retry logic.

Installation

Install the Printivo .NET SDK via NuGet Package Manager.

.NET CLI Package Manager PackageReference
# .NET CLI
dotnet add package Printivo.Client

# Or via Package Manager Console
# Install-Package Printivo.Client

# Or add to your .csproj
# <PackageReference Include="Printivo.Client" Version="1.*" />

Requirements

Quick Start

Initialize the client and make your first API call in just a few lines of code.

Setup
using Printivo.Client;

// Initialize the client with your API key
var client = new PrintivoClient("your_api_key");

// Or configure with options
var client = new PrintivoClient(options =>
{
    options.ApiKey = "your_api_key";
    options.BaseUrl = "https://api.printivo.cloud";
    options.Timeout = TimeSpan.FromSeconds(30);
    options.MaxRetries = 3;
});

Generate QR Codes

Create QR codes with full control over content type, styling, and output format.

Basic Styled vCard
// Generate a simple URL QR code
var qrImage = await client.QrCodes.GenerateAsync(new QrCodeRequest
{
    Content = "https://example.com",
    ContentType = QrContentType.Url,
    Size = 400,
    Format = OutputFormat.Png,
    ErrorCorrection = ErrorCorrectionLevel.M
});

// Save to file
await File.WriteAllBytesAsync("qrcode.png", qrImage);

// Generate styled QR code
var styledQr = await client.QrCodes.GenerateAsync(new QrCodeRequest
{
    Content = "https://example.com",
    ContentType = QrContentType.Url,
    Size = 600,
    Format = OutputFormat.Svg,
    ForegroundColor = "#1e40af",
    BackgroundColor = "#ffffff",
    ModuleShape = ModuleShape.Rounded,
    ErrorCorrection = ErrorCorrectionLevel.H
});

// Save SVG
await File.WriteAllBytesAsync("styled-qr.svg", styledQr);

Render ZPL Labels

Convert ZPL code to high-quality PNG or PDF images.

Basic Shipping Label
// Render a ZPL label to PNG
var labelImage = await client.Labels.RenderAsync(new LabelRequest
{
    Zpl = @"^XA
^FO50,50^A0N,40,40^FDShipping Label^FS
^FO50,120^BY3^BCN,100,Y,N,N^FD12345678^FS
^FO50,260^FDJohn Doe^FS
^FO50,310^FD123 Main Street^FS
^FO50,360^FDNew York, NY 10001^FS
^XZ",
    Dpi = 203,
    Format = OutputFormat.Png,
    Width = 4.0,
    Height = 6.0
});

await File.WriteAllBytesAsync("shipping-label.png", labelImage);

// Render to PDF for printing
var labelPdf = await client.Labels.RenderAsync(new LabelRequest
{
    Zpl = zplCode,
    Dpi = 300,
    Format = OutputFormat.Pdf,
    Width = 4.0,
    Height = 6.0
});

await File.WriteAllBytesAsync("label.pdf", labelPdf);

Generate Barcodes

Create barcodes of any supported type with validation and custom sizing.

EAN-13 Code 128 QR
// Generate an EAN-13 barcode
var barcode = await client.Barcodes.GenerateAsync(new BarcodeRequest
{
    Data = "1234567890128",
    Type = BarcodeType.EAN13,
    Width = 300,
    Height = 150,
    ShowText = true,
    Format = OutputFormat.Png
});

await File.WriteAllBytesAsync("ean13.png", barcode);

// Generate a Code 128 barcode
var code128 = await client.Barcodes.GenerateAsync(new BarcodeRequest
{
    Data = "SHIP-2024-001",
    Type = BarcodeType.Code128,
    Width = 400,
    Height = 100,
    ShowText = true
});

await File.WriteAllBytesAsync("code128.png", code128);

Error Handling

The SDK provides typed exceptions for easy error handling.

Error Handling
try
{
    var qr = await client.QrCodes.GenerateAsync(request);
}
catch (PrintivoAuthenticationException)
{
    // Invalid or missing API key (401)
    Console.WriteLine("Check your API key.");
}
catch (PrintivoRateLimitException ex)
{
    // Rate limit exceeded (429)
    Console.WriteLine($"Rate limited. Retry after {ex.RetryAfter}");
}
catch (PrintivoValidationException ex)
{
    // Invalid request parameters (400)
    foreach (var error in ex.Errors)
        Console.WriteLine($"{error.Field}: {error.Message}");
}
catch (PrintivoApiException ex)
{
    // Other API errors (5xx, etc.)
    Console.WriteLine($"API error: {ex.StatusCode} - {ex.Message}");
}

ASP.NET Core Integration

Register the Printivo client in your dependency injection container.

Program.cs Usage
// In Program.cs or Startup.cs
builder.Services.AddPrintivo(options =>
{
    options.ApiKey = builder.Configuration["Printivo:ApiKey"];
    options.BaseUrl = "https://api.printivo.cloud";
});

// Then inject IPrintivoClient in your services
public class MyService
{
    private readonly IPrintivoClient _printivo;

    public MyService(IPrintivoClient printivo)
    {
        _printivo = printivo;
    }

    public async Task<byte[]> GenerateProductQrCode(string productUrl)
    {
        return await _printivo.QrCodes.GenerateAsync(new QrCodeRequest
        {
            Content = productUrl,
            ContentType = QrContentType.Url,
            Size = 400
        });
    }
}

Start Building with .NET

Install the NuGet package and start generating QR codes, labels, and barcodes in minutes.

An unhandled error has occurred. Reload X