Print ZPL labels from Java
Java's HttpClient can post ZPL. No printer JAR is required on the server. The agent prints the queue you name with printer_code.
For Java services that already build ZPL
Overview
java.awt.print and Java Print Service see printers on the JVM's host. A cloud JVM does not have the warehouse Zebra. HttpClient posts the ZPL instead. The marketing site lists an official Java SDK; this is the REST body it would send.
Use StandardCharsets.UTF_8 for ZPL that declares ^CI28. Base64 with the JDK encoder, no line breaks, because the API asks for standard base64.
Close the printer choice in your own table of site to printer_code. Java system printers are not that table.
Create the job with POST /v1/print-jobs, an Authorization: Bearer header, printer_code, content_type pdf or raw, and exactly one of content or content_url. The free plan is 100 jobs a month on one computer.
Integration steps
- 01
Create an API key on the server
Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.
- 02
Install the agent beside the printer
Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.
- 03
POST /v1/print-jobs
content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.
- 04
Reuse the idempotency key on retry
A new key means a second physical print. HTTP 409 means the same key was reused with a different body.
- 05
Read the job before you tell the user
GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.
Java
// Java ZPL label
var json = """
{"printer_code":%d,"content_type":"raw",\"content\":\"" + zplBase64 + "\","copies":1}
""".formatted(printerCode);
var req = HttpRequest.newBuilder(URI.create("https://api.printbase.cloud/v1/print-jobs"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.header("Idempotency-Key", idempotencyKey)
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
if (res.statusCode() >= 300) throw new IllegalStateException(res.body());
// {"id":"job_abc","status":"queued"}
Details for this setup
No line-wrapped base64
Mime encoder with getMimeEncoder inserts line breaks. Use getEncoder so the JSON string is one line.
Timeouts
Set a connect and request timeout of a few seconds. Do not use the printer as a synchronous user-facing transaction.
Questions
javax.print?
It prints on the machine running the JVM. Use it only for a local desktop app. Servers should call the API.
Spring? in this setup
See the Spring Boot page. The body is the same. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Zebra's Java SDK?
That SDK talks to printers it can reach. It is optional and separate. This HTTP call does not use it.
Copies and ^PQ?
The agent may insert ^PQ for a simple label. If you already set ^PQ, it leaves the payload alone.
Free plan: 100 jobs a month on one computer, no card.