Add Barcode to PDF
Barcode → Add Barcode to PDF
The Add Barcode to PDF API embeds barcodes or QR codes into your PDFs. You send the PDF as Base64 (docContent), docName, the text to encode, barcodeType (e.g. qrCode, code128, dataMatrix), pages (e.g. 1-3 or all), alignment (alignX, alignY), and optional size and margin settings. The API returns the PDF with the barcode placed on the chosen pages. Use the tester below to try it; more details are in the sections that follow.
Try the Add Barcode to PDF API
:::note Quick reference
Endpoint: POST /api/v2/addbarcode · Required: api-key, docContent, docName, text, barcodeType, pages, alignX, alignY, hideText
:::
:::info Try it live Use the form below to send your API key, PDF (Base64), barcode content, type, target pages, and alignment. The response is the modified PDF with the barcode embedded. No code required—fill the fields and click Send request. :::
Overview, parameters, and use cases
- Overview
- Parameters
- Use cases
What is Add Barcode to PDF?
This endpoint places one or more barcodes or QR codes onto specified pages of a PDF. You choose the encoded text, barcode type (e.g. QR Code, Code128, DataMatrix), target pages, and position via horizontal and vertical alignment. Optional settings control size (mm or points), margins, opacity, and whether the human-readable text appears above or below the barcode.
Key features
- 150+ barcode types – Including QR Code, Code128, DataMatrix, PDF417, Aztec, HanXin, Code39, EAN13/EAN8, UPC-A/UPC-E and more.
- Flexible placement – alignX (Left, Center, Right) and alignY (Top, Middle, Bottom) with optional margins in mm or points.
- Page targeting – Use pages (e.g.
1-3,all) to add the barcode only where needed. - Size and opacity – heightInMM / widthInMM or heightInPt / widthInPt; opacity 0–100. Use 0 for auto size where supported.
:::tip Best for Use for invoices, tickets, labels, or any PDF that needs scannable codes. Combine with Read Barcode from PDF to verify, or Create Barcode if you only need a standalone barcode image. :::
API parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| api-key | string | Yes | Your PDF4me API key, Base64 encoded. Get it from the dashboard. |
| docContent | base64 | Yes | PDF file content (Base64). |
| docName | string | Yes | Output file name (e.g. output.pdf). |
| text | string | Yes | Text to encode in the barcode. |
| barcodeType | string | Yes | e.g. qrCode, code128, dataMatrix, aztec, hanxin, pdf417, code39, ean13, ean8, upcA, upcE. |
| pages | string | Yes | Target pages, e.g. 1-3 or all. |
| alignX | string | Yes | Horizontal alignment: Left, Center, Right. |
| alignY | string | Yes | Vertical alignment: Top, Middle, Bottom. |
| hideText | boolean | Yes | Whether to hide the human-readable barcode text. |
| heightInMM, widthInMM | string | No | Size in mm (0 = auto). |
| marginXInMM, marginYInMM | string | No | Margins in mm. |
| heightInPt, widthInPt | string | No | Size in points. |
| marginXInPt, marginYInPt | string | No | Margins in points. |
| opacity | integer | No | 0–100. |
| displayText | string | No | above or below. |
| showOnlyInPrint, isTextAbove | boolean | No | Print-only visibility; text above barcode. |
| IsAsync | boolean | No | Enable asynchronous processing. |
When to use Add Barcode to PDF
- Invoices and bills – Add QR or Code128 for payment or reference numbers.
- Tickets and passes – Embed codes for validation or links.
- Labels and packaging – Place barcodes on PDFs used for printing labels.
- Forms and applications – Add unique identifiers or tracking codes to each page.
- Batch processing – Use pages and alignment to add consistent barcodes across many PDFs.
:::info Need the full API? For request/response schemas and code samples, see Add Barcode to PDF in the PDF4me API docs. :::
Prerequisites
Before using this endpoint, make sure you have:
- A valid PDF4me API key (Get your API Key)
- A PDF document in Base64 format or a public URL to a PDF file
- The barcode type and text you want to encode
Response Format
The API returns a JSON response with:
- File Content: Binary content of the processed PDF document with embedded barcodes (Base64 encoded)
- File Name: Filename for the processed PDF document