本服务提供高性能 ZPL 渲染接口。所有接口均采用 POST 方法,接收 JSON 载荷。
curl -X POST http://localhost:8080/render/png \
-H "Content-Type: application/json" \
-d '{"zpl": "^XA...^XZ", "width_dots": 812, "height_dots": 1218, "dpmm": 8}'
import requests
def render_label():
url = "http://localhost:8080/render/pdf"
payload = {
"zpl": "^XA...^XZ",
"width_dots": 812, "height_dots": 1218,
"width_mm": 101.6, "height_mm": 152.4, "dpmm": 8
}
res = requests.post(url, json=payload)
if res.status_code == 200:
with open("label.pdf", "wb") as f: f.write(res.content)
if __name__ == "__main__":
render_label()
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Paths;
public class ZebrashClient {
public static void main(String[] args) throws Exception {
String json = "{\"zpl\": \"^XA...^XZ\", \"width_dots\": 812, \"height_dots\": 1218, \"dpmm\": 8}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:8080/render/png"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
client.send(request, HttpResponse.BodyHandlers.ofFile(Paths.get("label.png")));
}
}