Business

Shipping label PDF generator API

A USPS First-Class label with postage-paid block, ship-to address and tracking barcode — one per parcel.

Generate a clean shipping label PDF for every parcel from your fulfilment system. Pass the postage details, return and ship-to addresses and tracking number, and PDFgen renders a USPS-style label with a tracking barcode strip.

One reusable template covers every shipment, so high-volume order fulfilment is just one API call per package.

Generate a USPS Shipping Label PDF via the API

POST your data to /api/v1/generate and get a PDF back. Copy-paste an example, swap in your API key, and loop over a list to render thousands — one usps shipping label per record.

curl -X POST https://pdfgen.com/api/v1/generate \
-H "Authorization: Bearer pdfg_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"html": "<div style=\"padding:18px;font-family:Arial,Helvetica,sans-serif;color:#000;\">\n <div style=\"max-width:400px;margin:0 auto;border:1px solid #000;\">\n <div style=\"display:flex;border-bottom:3px solid #000;\">\n <div style=\"width:64px;border-right:1px solid #000;text-align:center;padding:6px 0;\">\n <span style=\"font-size:46px;font-weight:800;line-height:1;\">{{mailClassCode}}</span>\n </div>\n <div style=\"flex:1;padding:6px 8px;font-size:10px;line-height:1.4;\">\n <p style=\"margin:0;font-weight:700;\">US POSTAGE AND FEES PAID</p>\n <p style=\"margin:1px 0 0;font-weight:700;\">{{mailClass}}</p>\n <p style=\"margin:3px 0 0;\">{{mailedDate}}</p>\n <p style=\"margin:0;\">Mailed from ZIP {{originZip}}</p>\n <p style=\"margin:0;\">{{packageRate}}</p>\n <p style=\"margin:5px 0 0;border-top:1px solid #000;padding-top:3px;\">{{priceClass}}</p>\n </div>\n <div style=\"width:84px;border-left:1px solid #000;padding:6px;text-align:center;\">\n <div style=\"width:58px;height:58px;margin:0 auto;background:repeating-conic-gradient(#000 0% 25%, #fff 0% 50%) 0 0 / 7px 7px;\"></div>\n <p style=\"margin:4px 0 0;font-size:8px;\">{{postageId}}</p>\n </div>\n <div style=\"width:16px;border-left:1px solid #000;position:relative;\">\n <span style=\"position:absolute;top:50%;left:50%;transform:translate(-50%,-50%) rotate(90deg);white-space:nowrap;font-size:9px;color:#444;\">{{provider}}</span>\n </div>\n </div>\n <div style=\"background:#000;color:#fff;text-align:center;padding:7px;font-size:18px;font-weight:800;letter-spacing:1px;\">{{bannerText}}</div>\n <div style=\"padding:8px 12px;font-size:9px;color:#555;line-height:1.4;\">\n <p style=\"margin:0;\">{{from.name}}</p>\n <p style=\"margin:0;white-space:pre-line;\">{{from.address}}</p>\n </div>\n <div style=\"padding:18px 14px 30px;min-height:118px;\">\n <p style=\"margin:0 0 8px;font-size:11px;font-weight:700;\">SHIP TO:</p>\n <p style=\"margin:0;font-size:15px;font-weight:700;line-height:1.45;\">{{to.name}}</p>\n <p style=\"margin:0;font-size:15px;font-weight:700;line-height:1.45;white-space:pre-line;\">{{to.address}}</p>\n <p style=\"text-align:right;font-size:24px;font-weight:800;font-style:italic;margin:6px 0 0;\">{{brand}}</p>\n </div>\n <div style=\"border-top:3px solid #000;text-align:center;padding:7px;font-size:15px;font-weight:800;letter-spacing:1px;\">USPS TRACKING #</div>\n <div style=\"padding:12px 16px 16px;text-align:center;\">\n <div style=\"height:58px;background:repeating-linear-gradient(90deg,#000 0 2px,#fff 2px 4px,#000 4px 5px,#fff 5px 9px,#000 9px 12px,#fff 12px 14px);\"></div>\n <p style=\"margin:8px 0 0;font-size:13px;letter-spacing:2px;font-weight:700;\">{{tracking}}</p>\n </div>\n </div>\n</div>",
"engine": "handlebars",
"format": "A5",
"data": {
"mailClassCode": "F",
"mailClass": "FIRST-CLASS",
"mailedDate": "Jun 02 2026",
"originZip": "55987",
"packageRate": "3oz First-Class PKG Rate",
"priceClass": "CommercialBasePrice",
"postageId": "071S00840297",
"provider": "endicia.com",
"bannerText": "USPS FIRST-CLASS PKG",
"from": {
"name": "Northwind Goods",
"address": "120 Market St, San Francisco, CA 94103"
},
"to": {
"name": "Your Name",
"address": "123 Address St.\nCity, State 5555"
},
"brand": "Etsy",
"tracking": "9400 1108 9822 6486 0582 87"
}
}' --output shipping-label.pdf

Working in another language? Follow a full guide for your stack:

What you can build

  • Printing a label for every order at pack time
  • Generating labels from a WMS or order-management system
  • Batch-producing labels for a day’s shipments
  • Re-printing a damaged or lost label on demand

Frequently asked questions

Does this create real USPS postage?
No — it formats a USPS-style label layout. Pair it with a postage/carrier API for valid tracking numbers and paid postage, then pass those values into the template.
Can I render a scannable tracking barcode?
The template shows a barcode-style strip. For a scannable code, insert a barcode image/SVG generated from your tracking number and pass it in your data.
Can I generate labels in bulk?
Yes — loop over the day’s shipments and call the API once per parcel to get one label PDF each.

Related templates

Ship your usps shipping label PDF endpoint today

Generate this template with AI, tweak it to match your brand, then render at scale with a single API call — no headless browsers to babysit.