Skip to main content

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

ParameterDescriptionExample
widthLabel width, in the unit given by unit (inches by default).4
heightLabel height, in the unit given by unit (inches by default).6
pdfBase64The PDF file, encoded as a single base64 string (no data-URL prefix, no line breaks).Sample download

Page selection, scale, and rotation

ParameterRequiredDescriptionExample
pagesoptionalWhich pages to convert. Accepts:
  • a single page number (1 is the first page)
  • a comma-separated list (1,3,5)
  • all for every page
Defaults to 1. Each converted page becomes its own ZPL label in the response.
all
scaleoptionalHow the (optionally cropped) PDF page is fitted onto the label:
  • none (default) — no resize. The ZPL graphic is the PDF page size after crop.
  • contain — fit the whole page on the label, keep aspect ratio, letterbox if needed.
  • cover — fill the label, keep aspect ratio. Edges that overflow the label are clipped.
  • fill — stretch to the label. Aspect ratio is not preserved.
  • fitToWidth — match label width, keep aspect ratio.
  • fitToHeight — match label height, keep aspect ratio.
contain
rotateoptionalRotate the result. One of 0 (default), 90 (right), 180, 270 (left).90
unitoptionalUnit for width, height, and the crop parameters. One of:
  • in (default) — inches
  • mm — millimeters
  • dots — printer dots at the requested dpi
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
Diagram of cropTop, cropRight, cropBottom, and cropLeft on a PDF page
ParameterRequiredDescriptionExample
cropLeftoptionalAmount to remove from the left edge of the PDF page.0.25
cropRightoptionalAmount to remove from the right edge.0.25
cropTopoptionalAmount to remove from the top edge.0.5
cropBottomoptionalAmount to remove from the bottom edge.0.25

Order of operations

  1. The selected PDF page is rasterized at the requested dpi.
  2. Each crop side is chopped from that raster. Crop uses the original page orientation, not the rotated result.
  3. scale fits what remains onto width × height.
  4. rotate is 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.

tip

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..."
}
ParameterRequiredDescriptionExample
darknessoptionalInteger from 0 to 30. Sets printer darkness, the same as the darkness setting in the Zebra web UI or driver.15
dpioptionalPrinter resolution:
  • 203 (default) — 203 dpi / 8 dpmm, used by most Zebra printers
  • 300 — 300 dpi / 12 dpmm
  • 600 — 600 dpi / 24 dpmm
203
speedoptionalPrint speed in inches per second, integer from 2 to 12. Same as the print-rate setting in the Zebra web UI or driver.2
tip

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:

Sample Label printed on a Zebra label printer

Postman configuration

Refer to the following screenshots for Postman configuration details:

Postman Headers for PDF to ZPL API

Postman Body for PDF to ZPL API