Add Barcode to PDF - QR Code Integration API
PDF4me Add Barcode to PDF enables you to add professional barcodes and QR codes to PDF documents with precise positioning, sizing, and formatting controls. This API service processes PDF files and adds barcodes using Base64 encoding for secure transmission. With support for 150+ barcode types including QR codes, Code128, DataMatrix, Aztec, Hanxin, PDF417, and specialized formats, this solution is ideal for inventory management systems, shipping label automation, document tracking workflows, and enterprise barcode integration.
Authenticating Your API Request
To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.
Key Features
- Comprehensive Barcode Support: 150+ barcode types including QR codes, Code128, DataMatrix, Aztec, Hanxin, PDF417, postal codes, and specialized industry formats
- Precise Positioning Control: Place barcodes anywhere on PDF pages with pixel-perfect accuracy using both millimeter and point measurement systems
- Advanced Sizing Options: Flexible barcode dimensions with auto-sizing capabilities and custom width/height controls for optimal scanning performance
- Professional Text Management: Configure barcode text display, positioning (above/below), and visibility with customizable formatting options
- Opacity and Transparency: Adjust barcode transparency levels for watermark effects, document overlays, and professional presentation
- Enterprise Batch Processing: Add barcodes to multiple pages, documents, or entire document collections with automated processing workflows
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All barcode operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/addbarcode
Supported Barcode Types
Supports 150+ barcode types for comprehensive PDF integration.
Popular 1D Barcodes
- Code128 - Universal barcode (255 chars max)
- Code39 - Alphanumeric barcode (43 chars max)
- EAN13/EAN8 - Retail product codes (13/8 chars)
- UPC-A/UPC-E - North American retail (12/8 chars)
Popular 2D Barcodes
- QR Code - Mobile scanning (4,296 chars max)
- DataMatrix - High-density 2D (2,335 chars max)
- PDF417 - Large data capacity (2,710 chars max)
- Aztec - Excellent error correction (3,832 chars max)
Specialized Formats
- Postal Codes: USPS, Royal Mail, Australia Post, Deutsche Post
- Healthcare: HIBC, GS1 DataBar, Pharmacode
- Logistics: MaxiCode, SSCC-18, ITF-14, GS1-128
- QR Variants: Micro QR, iQR, rMQR
REST API Parameters
Complete list of parameters for the Add Barcode to PDF REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.
Required Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| docName* | String | Output PDF file name with .pdf extension | output.pdf |
| docContent* | Base64 | The content of the input PDF file encoded in Base64 | JVBERi... |
| text* | String | Text to be encoded in the barcode. Text length depends on barcode type | PDF4me Barcode Sample |
| barcodeType* | String | Barcode format type. Options: qrCode, code128, dataMatrix, aztec, hanxin, pdf417, code39, ean13, ean8, upcA, upcE | qrCode |
| pages* | String | Target pages (e.g., "1-3", "all", "1", "1,3,5", "2-5", "1,3,7-10", "2-") | 1-3 |
| alignX* | String | Horizontal alignment: Left, Center, or Right | Right |
| alignY* | String | Vertical alignment: Top, Middle, or Bottom | Bottom |
| hideText* | Boolean | Hide barcode text label (true=hide, false=show text alongside barcode) | true |
Optional Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| heightInMM | String | Barcode height in millimeters (0 = auto) | 40 |
| widthInMM | String | Barcode width in millimeters (0 = auto) | 40 |
| marginXInMM | String | Horizontal margin in millimeters | 20 |
| marginYInMM | String | Vertical margin in millimeters | 20 |
| heightInPt | String | Barcode height in points | 113 |
| widthInPt | String | Barcode width in points | 113 |
| marginXInPt | String | Horizontal margin in points | 57 |
| marginYInPt | String | Vertical margin in points | 57 |
| opacity | Integer | Transparency level (0-100): 0=invisible, 100=fully opaque | 100 |
| displayText | String | Text position: above or below | below |
| showOnlyInPrint | Boolean | Show only in print (true) or in view and print (false) | false |
| isTextAbove | Boolean | Text above barcode (true) or below (false) | false |
| async | Boolean | Enable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location header | true |
Output
The PDF4me Add Barcode to PDF REST API returns different responses based on the processing mode. The API returns the PDF as a Base64-encoded string in JSON format, not as binary data.
- Success Response
- Asynchronous Processing
- Error Responses
- Response Format Details
Synchronous Processing (Default)
When async is not set or set to false, the API processes the request immediately:
Status Code: 200 OK
Content-Type: application/json
Response Body:
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg=="
}
Response Fields:
- docName (string): The output PDF file name
- docContent (string): The PDF file with barcode added, encoded as Base64 string
How to Use:
- Extract the
docContentfield from the JSON response - Decode the Base64 string to get the binary PDF data
- Save or process the PDF file as needed
Example (JavaScript):
const response = await fetch(url, options);
const data = await response.json();
const pdfBytes = atob(data.docContent); // Decode Base64
// Save or process pdfBytes
Asynchronous Processing
When async: true is set, the API processes the request asynchronously:
Status Code: 202 Accepted
Response Headers:
Location: https://api.pdf4me.com/api/v2/addbarcode/poll/12345-abcde-67890
Polling Process:
- Extract the
Locationheader from the 202 response - Poll the URL using GET requests
- Continue polling until you receive a 200 OK status
- The final response contains the same JSON format with
docNameanddocContent(Base64)
Polling Example:
// Initial request returns 202 with Location header
const response = await fetch(url, options);
const location = response.headers.get('Location');
// Poll until complete
while (true) {
const pollResponse = await fetch(location, { headers: { 'Authorization': 'Basic ' + apiKey } });
if (pollResponse.status === 200) {
const data = await pollResponse.json();
// Process data.docContent (Base64 PDF)
break;
}
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
}
Error Responses
The API returns standard HTTP error codes with error details:
- Invalid request parameters
- Missing required fields
- Invalid Base64 encoding in
docContent - Invalid barcode type
- Invalid alignment values
- Invalid or missing API key
- API key not properly Base64 encoded in Authorization header
- Missing
Authorization: Basicheader
- Server-side processing error
- PDF processing failure
- Barcode generation failure
Error Response Format:
{
"error": "Error message describing what went wrong"
}
Response Format Details
Important: The API always returns JSON, never binary PDF data directly.
Response Structure:
{
"docName": "string", // Output PDF filename
"docContent": "string" // Base64-encoded PDF content
}
Content-Type Header:
- Success:
application/json - The PDF is embedded as a Base64 string within the JSON response
Why Base64?
- JSON-safe encoding for binary data
- Easy to transmit over HTTP
- Compatible with all programming languages
- Can be directly embedded in JSON without escaping issues
Decoding Base64 to PDF:
JavaScript/Node.js:
const base64 = response.docContent;
const binary = atob(base64); // Browser
// OR
const binary = Buffer.from(base64, 'base64').toString('binary'); // Node.js
Python:
import base64
pdf_bytes = base64.b64decode(response['docContent'])
with open('output.pdf', 'wb') as f:
f.write(pdf_bytes)
C#:
byte[] pdfBytes = Convert.FromBase64String(response.docContent);
File.WriteAllBytes("output.pdf", pdfBytes);
Request Example
Header
Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY
Note:
- Get your API key from the PDF4me Dashboard
- The API key must be Base64 encoded and prefixed with "Basic " in the Authorization header
- Example: If your API key is
abc123, encode it to Base64 and useAuthorization: Basic YWJjMTIz
Payload
Basic Example (Required Fields Only):
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"text": "PDF4me Barcode Sample",
"barcodeType": "qrCode",
"pages": "1-3",
"alignX": "Right",
"alignY": "Bottom",
"hideText": true
}
Advanced Example (With All Optional Fields):
{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"text": "PDF4me Barcode Sample",
"barcodeType": "qrCode",
"pages": "1-3",
"alignX": "Right",
"alignY": "Bottom",
"hideText": true,
"heightInMM": "40",
"widthInMM": "40",
"marginXInMM": "20",
"marginYInMM": "20",
"heightInPt": "113",
"widthInPt": "113",
"marginXInPt": "57",
"marginYInPt": "57",
"opacity": 100,
"displayText": "below",
"showOnlyInPrint": false,
"isTextAbove": false,
"async": true
}
Code Samples
The PDF4me Add Barcode to PDF REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:
- C#
- Java
- JavaScript
- Python
- Salesforce
- Google Script
- n8n
- AWS Lambda
Google Script Sample
Google Apps Script implementation for Google Workspace integration:
Industry Use Cases & Applications
- E-commerce & Retail
- Logistics & Shipping
- Healthcare & Medical
- Government & Compliance
- Education & Libraries
- Business & Finance
E-commerce & Retail Use Cases
- Product Catalogs: Generate barcodes for inventory management and product identification
- Price Tags: Create dynamic pricing with barcode integration for automated checkout
- Order Tracking: Add tracking codes to shipping documents for real-time package monitoring
- Inventory Systems: Bulk barcode generation for warehouse management and stock control
Logistics & Shipping Use Cases
- Shipping Labels: Add tracking barcodes to delivery documents for package traceability
- Package Tracking: Generate unique identifiers for each shipment across the supply chain
- Warehouse Management: Create barcodes for bin locations and product identification
- Supply Chain: Track products through entire distribution network with embedded codes
Healthcare & Medical Use Cases
- Patient Records: Add barcodes for quick patient identification and medical history access
- Medication Administration: Generate barcodes for drug tracking and dosage verification
- Medical Equipment: Tag equipment with maintenance barcodes for asset management
- Lab Results: Add barcodes to test result documents for secure patient data linking
Government & Compliance Use Cases
- ID Documents: Add security barcodes to driver's licenses and passports for verification
- Tax Documents: Generate tracking codes for tax forms and compliance monitoring
- Compliance Forms: Add barcodes for regulatory tracking and audit trails
- Public Records: Create searchable document identifiers for government databases
Education & Libraries Use Cases
- Student IDs: Generate barcodes for student identification and campus access control
- Library Systems: Add barcodes to books and resources for automated checkout systems
- Exam Papers: Create unique identifiers for test documents and academic integrity
- Campus Services: Track equipment and resource usage across educational facilities
Business & Finance Use Cases
- Invoice Processing: Add barcodes for automated invoice handling and payment processing
- Document Management: Create unique identifiers for business documents and records
- Asset Tracking: Generate barcodes for equipment and assets across organizations
- Audit Trails: Add tracking codes for compliance documentation and financial records