Primeiro, inscreva-se no plano básico para obter uma chave de API gratuita para desenvolvimento. Por favor, substitua API_KEY
no exemplo de código abaixo pela sua própria chave de API.
Converter um arquivo PDF para ZPL usando PHP
Abaixo está um exemplo de código que pode ser usado para converter um arquivo PDF para ZPL:
<?php
function callPdfToZplAPI($width, $height, $filename) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://html-to-zpl.p.rapidapi.com/pdf2zpl");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"X-RapidAPI-Host: html-to-zpl.p.rapidapi.com",
"X-RapidAPI-Key: API_KEY",
"content-type: application/json"
]);
$pdfRaw = file_get_contents($filename);
$pdfBase64 = base64_encode($pdfRaw);
$data = [
"width" => $width,
"height" => $height,
"pdfBase64" => $pdfBase64
];
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$zpl = callPdfToZplAPI(4, 6, "test.pdf");
echo $zpl;
Converter HTML para ZPL usando PHP
Exemplo de código para converter HTML para ZPL usando PHP:
<?php
function callHtmlToZplAPI($width, $height, $html)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://html-to-zpl.p.rapidapi.com/html2zpl");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"X-RapidAPI-Host: html-to-zpl.p.rapidapi.com",
"X-RapidAPI-Key: API_KEY",
"content-type: application/json"
]);
$data = [
"width" => $width,
"height" => $height,
"html" => $html
];
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$html = "<div style='width: 4in; height: 6in; padding: 1in; box-sizing: border-box; text-align: center;'>";
$html .= " <h1>Hello World!<h1>";
$html .= " <h2>This label was generated by the htmltozpl.com API</h2>";
$html .= "</div>";
$zpl = callHtmlToZplAPI(4, 6, $html);
echo $zpl;