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 https://html-to-zpl.p.rapidapi.com/pdf2zpl
The API key provided by Rapid API must be set in the HTTP header X-RapidAPI-Key
.
Parameters
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 Name | Required | Description | Example |
---|---|---|---|
height | required | The height of the label, in inches. | 6 |
width | required | The width of the label, in inches. | 4 |
pdfBase64 | required | A base64 encoded PDF file. | Sample Download |
pages | optional | This parameter allows you to selectively convert pages from a multi-page PDF document into ZPL format. Acceptable values include:
1 (only the first page is converted). | all 1,3,5 |
rotate | optional | The number of degrees to rotate. Must be one of:
| 90 |
scale | optional | Scaling/zooming options:
| contain |
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.
Print Quality Settings
Parameter Name | Required | Description | Example |
---|---|---|---|
darkness | optional | An 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. | 15 |
dpi | optional | The Zebra printer resolution in dpi (dots per inch):
| 203 |
speed | optional | An 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. | 2 |
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:
wget https://www.htmltozpl.com/img/sample-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 https://html-to-zpl.p.rapidapi.com/pdf2zpl \
--header 'content-type: application/x-www-form-urlencoded' \
--header 'x-rapidapi-host: html-to-zpl.p.rapidapi.com' \
--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 192.168.1.234 9100 < sample-label.zpl
This is the resulting label printed on a Zebra GK420t:
Postman Configuration
Refer to the following screenshots for Postman configuration details: