Skip to content

Other languages

This page shows how to convert labels from languages that don’t have their own LabelZoom package: PowerShell, and VB.NET through the .NET package.

  • Optional: Get an API key. Without one, output has a watermark. See Authentication.
  • To print, you need a network printer that accepts raw printing on TCP port 9100. Most Zebra printers do by default.

These examples run in Windows PowerShell 5.1 and PowerShell 7 or later, with no modules to install. Each one reads your API key from the LABELZOOM_API_KEY environment variable and sends the Authorization header only when the key is set.

For complete scripts with parameters, see the PowerShell samples on GitHub.

Terminal window
# Windows PowerShell 5.1 only: turn on TLS 1.2. PowerShell 7 doesn't need this line.
[Net.ServicePointManager]::SecurityProtocol =
[Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$headers = @{ Accept = '*/*' }
if ($env:LABELZOOM_API_KEY) { $headers.Authorization = "Bearer $env:LABELZOOM_API_KEY" }
$params = @{ label = @{ width = 4; height = 6 }; dpi = 203 } | ConvertTo-Json -Compress
$uri = 'https://api.labelzoom.com/api/v2/convert/zpl/to/pdf?params=' + [Uri]::EscapeDataString($params)
Invoke-WebRequest -Uri $uri -Method Post -Headers $headers -UseBasicParsing `
-ContentType 'text/plain' `
-Body '^XA^FO50,50^ADN,36,20^FDLabelZoom^FS^XZ' `
-OutFile label.pdf

Options go in one params query parameter that holds JSON. Leave out label to use the label’s own size. For every option, see Conversion parameters.

Terminal window
$params = @{ pdf = @{ pageNumber = 0 } } | ConvertTo-Json -Compress # 0-based; omit to convert every page
$uri = 'https://api.labelzoom.com/api/v2/convert/pdf/to/zpl?params=' + [Uri]::EscapeDataString($params)
Invoke-WebRequest -Uri $uri -Method Post -Headers $headers -UseBasicParsing `
-ContentType 'application/pdf' `
-InFile shipping-label.pdf `
-OutFile label.zpl

Use -InFile and -OutFile for files. They send and save the bytes unchanged, which PDF, image, and printer-language output need; see Binary output.

Terminal window
$template = '^XA^FO50,50^A0N,30,30^FD{name}^FS^FO50,100^A0N,30,30^FD{sku}^FS^XZ'
$params = @{
data = @( # one label per record
@{ name = 'ACME Corp'; sku = '12345' },
@{ name = 'Globex'; sku = '67890' }
)
} | ConvertTo-Json -Compress -Depth 5
$uri = 'https://api.labelzoom.com/api/v2/convert/zpl/to/zpl?params=' + [Uri]::EscapeDataString($params)
$response = Invoke-WebRequest -Uri $uri -Method Post -Headers $headers -UseBasicParsing `
-ContentType 'text/plain' -Body $template
$response.Content

Pass -Depth to ConvertTo-Json. Its default depth is 2, so without it a record that holds a nested value is cut off. For the placeholder syntax, see Merge fields.

Terminal window
$bytes = [IO.File]::ReadAllBytes((Resolve-Path label.zpl).ProviderPath)
$client = New-Object Net.Sockets.TcpClient
try {
$client.Connect('PRINTER_IP', 9100)
$client.GetStream().Write($bytes, 0, $bytes.Length)
} finally {
$client.Close()
}

Replace PRINTER_IP with your printer’s IP address or hostname.

Terminal window
try {
Invoke-WebRequest -Uri $uri -Method Post -Headers $headers -UseBasicParsing `
-ContentType 'text/plain' -Body $template -OutFile label.zpl
} catch {
$status = $_.Exception.Response.StatusCode.value__
$message = $_.ErrorDetails.Message
if ($message -and $message.TrimStart().StartsWith('{')) { $message = ($message | ConvertFrom-Json).message }
Write-Error "HTTP ${status}: $message"
}

The error body is JSON with a message field. If the response is 429, wait and retry; see Rate limits and plans. For status codes, see Errors.

VB.NET uses the .NET package, LabelZoom.Sdk. It works in .NET Framework 4.6.1 or later, .NET Core 2.0 or later, and .NET 5 or later. For a complete program, see the VB.NET sample on GitHub.

Add the package to your project:

Terminal window
dotnet add package LabelZoom.Sdk

In Visual Studio, you can instead search for LabelZoom.Sdk in Manage NuGet Packages.

Imports LabelZoom.Sdk
Using client As New LabelZoomClient() ' reads LABELZOOM_API_KEY
Dim result = Await client.Convert() _
.FromZpl("^XA^FO50,50^ADN,36,20^FDLabelZoom^FS^XZ") _
.ToPdf() _
.WithDpi(203) _
.ExecuteAsync()
result.Save("label.pdf")
End Using

To pass a key explicitly, use New LabelZoomClient("API_KEY"). The client wraps an HttpClient, so create one client for your application and reuse it. Visual Basic has no Async Sub Main, so call .GetAwaiter().GetResult() on the task from Sub Main.

Dim result = Await client.Convert() _
.FromFile(SourceFormat.Pdf, "shipping-label.pdf") _
.ToZpl() _
.ExecuteAsync()
Console.WriteLine(result.Text)

Write PDF, image, and printer-language (EPL, IPL, TSPL, DPL, SBPL) output as bytes (result.Bytes or result.Save), not text; see Binary output. For label size, page number, merge fields, and the other options, see the C# quickstart. The methods are the same in VB.NET.

Imports System.IO
Imports System.Net.Sockets
Dim bytes = File.ReadAllBytes("label.zpl")
Using tcp As New TcpClient("PRINTER_IP", 9100)
Using stream = tcp.GetStream()
stream.Write(bytes, 0, bytes.Length)
End Using
End Using

Replace PRINTER_IP with your printer’s IP address or hostname.

Try
Await client.Convert() _
.FromZpl("^XA^FO50,50^ADN,36,20^FDLabelZoom^FS^XZ") _
.ToPdf() _
.ExecuteAsync()
Catch e As LabelZoomException
Console.Error.WriteLine($"HTTP {CInt(e.StatusCode)}, request ID {e.RequestId}: {e.Message}")
End Try

The SDK retries 429 and 5xx responses automatically before it throws. To detect a request that needs a paid plan, catch LabelZoomForbiddenException and check IsPaidFeature. For status codes, see Errors.

To call the API with HttpClient instead of the SDK, send the label as the request body:

Imports System.IO
Imports System.Net.Http
Imports System.Net.Http.Headers
Dim apiKey = Environment.GetEnvironmentVariable("LABELZOOM_API_KEY")
Using http As New HttpClient()
http.DefaultRequestHeaders.Accept.ParseAdd("*/*")
' The API key is optional. Omit the Authorization header if it isn't set.
If Not String.IsNullOrEmpty(apiKey) Then
http.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", apiKey)
End If
Dim content As New ByteArrayContent(File.ReadAllBytes("shipping-label.pdf"))
content.Headers.ContentType = New MediaTypeHeaderValue("application/pdf")
Dim response = Await http.PostAsync(
"https://api.labelzoom.com/api/v2/convert/pdf/to/zpl", content)
response.EnsureSuccessStatusCode()
File.WriteAllBytes("label.zpl", Await response.Content.ReadAsByteArrayAsync())
End Using