PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/Guides/Print from your language or framework

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

  1. 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.

  2. 02

    Install the agent beside the printer

    Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.

  3. 03

    POST /v1/print-jobs

    content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.

  4. 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.

  5. 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.

Related guides

  • Print receipts from Spring Boot

    Print ESC/POS receipts from a Spring Boot service: build the bytes in a @Service, post them with RestClient or WebClient, and keep the API key in a property, not a request field.

  • Print raw ZPL from Go

    Go's net/http posts ZPL with no extra module. Base64 from encoding/base64. The agent prints the Zebra queue.

  • Print ZPL shipping labels to a Zebra ZD420

    Send ZPL to a Zebra ZD420 from your app. The agent writes raw bytes to the OS queue. No Browser Print port and no public IP.

  • Print ZPL labels from Node.js

    Build a ZPL string in Node.js and send it as raw base64. The agent does not render the label; the printer does.

Free plan: 100 jobs a month on one computer, no card.

Create a free accountRead the API docs
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds