Skip to main content

Convert PDF to ZPL

This API service can be used to convert PDF documents directly to ZPL code compatible with Zebra printers. It supports multi-page PDFs, and can also rotate and scale documents if required.

API Usage

The API method and endpoint is POST

The API key provided by Rapid API must be set in the HTTP header X-RapidAPI-Key.


The following parameters can be set via the body of a POST request, either as JSON (using the content-type application/json) or form-encoded (using the content-type: application/x-www-form-urlencoded header).

Parameter NameRequiredDescriptionExample
heightrequiredThe height of the label, in inches.6
widthrequiredThe width of the label, in inches.4
pdfBase64requiredA base64 encoded PDF file.Sample Download
pagesoptionalThis parameter allows you to selectively convert pages from a multi-page PDF document into ZPL format. Acceptable values include:
  • single page number (e.g., 1): Provide a single whole number if you wish to convert a specific page of your document. The number should correspond to the actual page number in the PDF.
  • comma-separated list of numbers (e.g., 1,2,3): If you want to convert multiple, but not all, pages of your PDF to ZPL, provide those page numbers as a comma-separated list.
  • all: Use this value if you want to convert all pages.
By default this parameter is set to 1 (only the first page is converted).
rotateoptionalThe number of degrees to rotate. Must be one of:
  • 0 - no rotation
  • 90 - rotate right
  • 180 - upside-down
  • 270 - rotate left
scaleoptionalScaling/zooming options:
  • contain - scales the PDF so that it fits entirely on the label, preserving the aspect ratio (no distortion).
  • cover - scales the PDF so that it covers the entire label, preserving the aspect ratio. This can cause the edges to be cropped.
  • fill - scales the PDF to the label, ignoring the aspect ratio. This can cause distortion if the aspect ratios don't match.
  • fitToWidth - scales the PDF so that the width matches the label, preserving its aspect ratio.
  • fitToHeight - scales the PDF so that the height matches the label, preserving its aspect ratio.

Make sure that the size of the PDF document matches the label size given in the width and height parameters exactly, otherwise some content might be cropped off.

Parameter NameRequiredDescriptionExample
darknessoptionalAn integer value between 0 and 30.
Sets the printer darkness. This is equivalent to setting the darkness in the Zebra printer web configuration or driver.
dpioptionalThe Zebra printer resolution in dpi (dots per inch):
  • 203 (default) - 203 dpi / 8 dpmm - used by most Zebra printers
  • 300 - 300 dpi / 12 dpmm
  • 600 - 600 dpi / 24 dpmm
speedoptionalAn integer value between 2 and 12 that determines the media speed during printing in inches per second.
This is equivalent to the corresponding print rate setting in the Zebra printer web configuration or driver.

Lowering the print speed improves the quality, especially for small fonts and barcodes.

Command Line Example (using curl)

First, let's download a sample 4x6" shipping label PDF:


The PDF file can be converted to base64 using the base64 tool on Linux and Mac OS X. Note that the -w0 parameter is required to omit any line breaks in the encoding process.

base64 -w0 sample-label.pdf > sample-label.base64

You should now have a file sample-label.base64 in your current directory. If you open that file in a text editor, you should see a single long ASCII string. If you want to compare this file, you can download our reference.

We can now send the base64 encoded file to the PDF to ZPL conversion API with the following curl command. The parameter --data-urlencode [email protected] tells curl to use the content of the sample-label.base64 file in the pdfBase64 API parameter. Please replace the API_KEY in the example with your key from Rapid API.

curl --request POST \
--url \
--header 'content-type: application/x-www-form-urlencoded' \
--header 'x-rapidapi-host:' \
--header 'x-rapidapi-key: API_KEY' \
--data width=4 \
--data height=6 \
--data-urlencode [email protected] \
> sample-label.zpl

If everything went well, you will have a sample-label.zpl in your current directory. This file contains the rendering of the PDF in ZPL and can be sent directly to a network attached printer using the tool netcat:

nc -N 9100 < sample-label.zpl

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