Convert PDF to ZPL
This API converts PDF documents to ZPL that Zebra printers can print. It supports multi-page PDFs, and can crop, rotate, and scale each page before conversion.
Typical uses include printing carrier shipping labels, packing slips, and other PDFs that were not designed as ZPL.
API usage
Endpoint: POST https://html-to-zpl.p.rapidapi.com/pdf2zpl
Set the API key from Rapid API in the X-RapidAPI-Key header.
Send parameters in the POST body as JSON (Content-Type: application/json) or as form fields (Content-Type: application/x-www-form-urlencoded). The response is raw ZPL.
Required parameters
| Parameter | Description | Example |
|---|---|---|
width | Label width, in the unit given by unit (inches by default). | 4 |
height | Label height, in the unit given by unit (inches by default). | 6 |
pdfBase64 | The PDF file, encoded as a single base64 string (no data-URL prefix, no line breaks). | Sample download |
Page selection, scale, and rotation
| Parameter | Required | Description | Example |
|---|---|---|---|
pages | optional | Which pages to convert. Accepts:
1. Each converted page becomes its own ZPL label in the response. | all |
scale | optional | How the (optionally cropped) PDF page is fitted onto the label:
| contain |
rotate | optional | Rotate the result. One of 0 (default), 90 (right), 180, 270 (left). | 90 |
unit | optional | Unit for width, height, and the crop parameters. One of:
| in |
cover can clip edges as a side effect of fitting. That is not the same as the crop parameters below, which trim the PDF page on purpose before scaling.
Crop PDF pages
Use cropLeft, cropRight, cropTop, and cropBottom to chop a margin off each side of the PDF page. Omitted sides default to 0. Values are non-negative numbers in the same unit as width and height (inches by default).
Crop is PDF-only. The HTML conversion path ignores these parameters.
When to crop
- Carrier shipping-label PDFs with extra whitespace or a letterhead above the 4×6 label
- Pages that include unprintable printer margins you do not want on the sticker
- Letter- or A4-sized documents where only the inner region should be printed
| Parameter | Required | Description | Example |
|---|---|---|---|
cropLeft | optional | Amount to remove from the left edge of the PDF page. | 0.25 |
cropRight | optional | Amount to remove from the right edge. | 0.25 |
cropTop | optional | Amount to remove from the top edge. | 0.5 |
cropBottom | optional | Amount to remove from the bottom edge. | 0.25 |
Order of operations
- The selected PDF page is rasterized at the requested
dpi. - Each crop side is chopped from that raster. Crop uses the original page orientation, not the rotated result.
scalefits what remains ontowidth×height.rotateis applied last.
Because crop runs before scale:
scale=contain(typical) — the remaining content is enlarged to fill the label. Use this when you trimmed whitespace and still want a full-size 4×6 (or other) sticker.scale=none(API default) — the ZPL graphic shrinks by the cropped amount. A 4×6 page cropped by 0.25″ on every side becomes a 3.5×5.5 label.
Keep the remaining width and height positive. Cropping more than the page size produces an empty or invalid result.
Try crop in the PDF to ZPL online demo. Load the sample shipping label, set a preset such as ¼″, and compare the preview with and without crop.
JSON example — trim a quarter inch from every side, then fit the rest on a 4×6 label:
{
"width": 4,
"height": 6,
"scale": "contain",
"cropLeft": 0.25,
"cropRight": 0.25,
"cropTop": 0.25,
"cropBottom": 0.25,
"pdfBase64": "JVBERi0xLjcK..."
}
Only the top of a page (for example a 1″ letterhead):
{
"width": 4,
"height": 6,
"scale": "contain",
"cropTop": 1,
"pdfBase64": "JVBERi0xLjcK..."
}
Print quality settings
| Parameter | Required | Description | Example |
|---|---|---|---|
darkness | optional | Integer from 0 to 30. Sets printer darkness, the same as the darkness setting in the Zebra web UI or driver. | 15 |
dpi | optional | Printer resolution:
| 203 |
speed | optional | Print speed in inches per second, integer from 2 to 12. Same as the print-rate setting in the Zebra web UI or driver. | 2 |
Lowering the print speed improves quality, especially for small fonts and barcodes.
Command-line example (curl)
Download a sample 4×6″ shipping-label PDF:
wget https://www.htmltozpl.com/img/sample-label.pdf
Encode it as base64. On Linux, -w0 omits line breaks. On macOS, base64 does not wrap by default:
base64 -w0 sample-label.pdf > sample-label.base64
You should now have a file sample-label.base64 containing a single long ASCII string.
You can download our reference to compare.
Send that file to the API as JSON. $(cat sample-label.base64) inserts the base64 string into the pdfBase64 field.
Replace API_KEY with your key from Rapid API.
curl --request POST \
--url https://html-to-zpl.p.rapidapi.com/pdf2zpl \
--header 'content-type: application/json' \
--header 'x-rapidapi-host: html-to-zpl.p.rapidapi.com' \
--header 'x-rapidapi-key: API_KEY' \
--data "{
\"width\": 4,
\"height\": 6,
\"pdfBase64\": \"$(cat sample-label.base64)\"
}" \
> sample-label.zpl
With crop — remove 0.25″ from every side, then scale the remaining content back onto the 4×6 label:
curl --request POST \
--url https://html-to-zpl.p.rapidapi.com/pdf2zpl \
--header 'content-type: application/json' \
--header 'x-rapidapi-host: html-to-zpl.p.rapidapi.com' \
--header 'x-rapidapi-key: API_KEY' \
--data "{
\"width\": 4,
\"height\": 6,
\"scale\": \"contain\",
\"cropLeft\": 0.25,
\"cropRight\": 0.25,
\"cropTop\": 0.25,
\"cropBottom\": 0.25,
\"pdfBase64\": \"$(cat sample-label.base64)\"
}" \
> sample-label-cropped.zpl
If the request succeeds, sample-label.zpl contains ZPL you can send to a network printer with netcat on macOS or Linux:
nc -N 192.168.1.234 9100 < sample-label.zpl
On Windows, use PowerShell:
$client = New-Object System.Net.Sockets.TcpClient("192.168.1.234", 9100)
$stream = $client.GetStream()
$bytes = [System.IO.File]::ReadAllBytes("sample-label.zpl")
$stream.Write($bytes, 0, $bytes.Length)
$stream.Close()
$client.Close()
This is the resulting label printed on a Zebra GK420t:
Postman configuration
Refer to the following screenshots for Postman configuration details:

