Skip to main content

Convert PDF to ZPL

This API is used to convert PDF documents directly to ZPL code compatible with Zebra printers.

To use this feature provide a base64 encoded PDF to the pdfBase64 parameter.

The API also support rotating and scaling the PDF document.

API Usage

The API endpoint is:

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

The following parameters are supported by the PDF to ZPL conversion API:

Parameter NameRequiredDescriptionExample
heightyesThe height of the label in inches.6
widthyesThe width of the label, units are inches.4
pdfBase64yesa base64 encoded PDF file.Sample Download
rotatenoThe number of degrees to rotate. Must be one of:
  • 0 - no rotation
  • 90 - rotate right
  • 180 - upside-down
  • 270 - rotate left
scalenoScaling/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.
dpinoThe 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
pagesnoThis 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).

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


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.

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