Skip to main content

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.

  • 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)
  • 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

ParameterTypeDescriptionExample
docName*StringOutput PDF file name with .pdf extensionoutput.pdf
docContent*Base64The content of the input PDF file encoded in Base64JVBERi...
text*StringText to be encoded in the barcode. Text length depends on barcode typePDF4me Barcode Sample
barcodeType*StringBarcode format type. Options: qrCode, code128, dataMatrix, aztec, hanxin, pdf417, code39, ean13, ean8, upcA, upcEqrCode
pages*StringTarget pages (e.g., "1-3", "all", "1", "1,3,5", "2-5", "1,3,7-10", "2-")1-3
alignX*StringHorizontal alignment: Left, Center, or RightRight
alignY*StringVertical alignment: Top, Middle, or BottomBottom
hideText*BooleanHide barcode text label (true=hide, false=show text alongside barcode)true

Optional Parameters

ParameterTypeDescriptionExample
heightInMMStringBarcode height in millimeters (0 = auto)40
widthInMMStringBarcode width in millimeters (0 = auto)40
marginXInMMStringHorizontal margin in millimeters20
marginYInMMStringVertical margin in millimeters20
heightInPtStringBarcode height in points113
widthInPtStringBarcode width in points113
marginXInPtStringHorizontal margin in points57
marginYInPtStringVertical margin in points57
opacityIntegerTransparency level (0-100): 0=invisible, 100=fully opaque100
displayTextStringText position: above or belowbelow
showOnlyInPrintBooleanShow only in print (true) or in view and print (false)false
isTextAboveBooleanText above barcode (true) or below (false)false
asyncBooleanEnable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location headertrue

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.

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:

  1. Extract the docContent field from the JSON response
  2. Decode the Base64 string to get the binary PDF data
  3. 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

Request Example

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 use Authorization: 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# (CSharp) Sample

Complete C# implementation for adding barcodes to PDF documents:

Industry Use Cases & Applications

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

Get Help