Read Barcode from PDF - Scanner & Extractor API
PDF4me Read Barcode from PDF enables you to extract and recognize various types of barcodes and QR codes from PDF documents using advanced OCR and barcode recognition technology. This API service processes PDF files and extracts barcode data with position coordinates, type information, and extracted text. The API receives PDF content through REST API calls, utilizing Base64 encoding for secure transmission. With support for 1D and 2D barcodes including QR codes, DataMatrix, PDF417, Code128, and specialized industry formats, this solution is ideal for document processing, inventory management, tracking systems, and workflow automation.
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 Recognition: Support for 1D and 2D barcodes including QR codes, DataMatrix, PDF417, Code128, postal codes, and specialized industry formats
- Seamless PDF Integration: Direct processing of PDF documents with support for all PDF versions and complex document structures
- Flexible Page Processing: Process specific pages, page ranges, or entire documents with selective barcode extraction capabilities
- Enterprise Batch Processing: Extract multiple barcodes from single or multiple pages with automated processing workflows
- Structured Data Output: Return barcode data in structured JSON format with position coordinates, type information, and metadata for easy system integration
Supported Barcode Types
The API supports a comprehensive range of barcode formats for reliable recognition:
1D Barcodes
- Code128 - Universal barcode format
- Code39 - Alphanumeric barcode
- Code93 - High-density barcode
- Codabar - Numeric barcode
- EAN8/EAN13 - European Article Number
- UPC-A/UPC-E - Universal Product Code
- Inter2of5 - Industrial 2 of 5
- PatchCode - Document processing codes
2D Barcodes
- QR Code - Quick Response codes
- DataMatrix - High-density 2D barcode
- PDF417 - Portable Data File
- MicroQRCode - Compact QR variant
Specialized Formats
- Postal Codes: Postnet, Planet, RM4SCC, Australia Post
- Intelligent Mail: USPS Intelligent Mail barcodes
- PharmaCode: Pharmaceutical barcodes
- RSS Codes: Reduced Space Symbology
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All barcode reading operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/ReadBarcodes
REST API Parameters
Complete list of parameters for the Read Barcode from 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 |
|---|---|---|---|
| docContent* | Base64 | PDF file content encoded in Base64 | JVBERi... |
| docName* | String | PDF file name with .pdf extension | document.pdf |
| barcodeType* | Array | Array of barcode types to detect. Use ["all"] for all types, or specific types like ["qrCode"], ["dataMatrix", "code128"] | ["all"] |
| pages* | String | Page options: "all", "1", "1,3,5", "2-5", "1,3,7-10", "2-" | all |
| IsAsync* | Boolean | Enable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location header | true |
Barcode Type Options
| Type | Description | Category |
|---|---|---|
all | Detect all supported barcode types | Universal |
unknown | Detect unknown barcode types | Universal |
qrCode | QR Code recognition | 2D |
dataMatrix | DataMatrix recognition | 2D |
pdf417 | PDF417 recognition | 2D |
code128 | Code128 recognition | 1D |
code39 | Code39 recognition | 1D |
ean13 | EAN13 recognition | 1D |
upca | UPC-A recognition | 1D |
all_1D | All 1D barcode types | 1D |
all_2D | All 2D barcode types | 2D |
Output
The PDF4me Read Barcode from PDF REST API returns different responses based on the processing mode. The API returns structured JSON data with barcode information.
- Success Response
- Asynchronous Processing
- Error Responses
- Response Format Details
Synchronous Processing (Default)
When IsAsync is not set or set to false, the API processes the request immediately:
Status Code: 200 OK
Content-Type: application/json
Response Body:
{
"barcodes": [
{
"type": "qrCode",
"text": "Barcode content",
"page": 1,
"x": 100,
"y": 200,
"width": 50,
"height": 50
}
]
}
Response Fields:
- barcodes (array): Array of detected barcode objects
- type (string): Barcode type (e.g., "qrCode", "dataMatrix", "code128")
- text (string): Extracted barcode content/text
- page (number): Page number where barcode was found
- x (number): X coordinate of barcode position
- y (number): Y coordinate of barcode position
- width (number): Width of the barcode
- height (number): Height of the barcode
Example (JavaScript):
const response = await fetch(url, options);
const data = await response.json();
data.barcodes.forEach(barcode => {
console.log(`Found ${barcode.type}: ${barcode.text} on page ${barcode.page}`);
});
Asynchronous Processing
When IsAsync: true is set, the API processes the request asynchronously:
Status Code: 202 Accepted
Response Headers:
Location: https://api.pdf4me.com/api/v2/ReadBarcodes/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 barcode data
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.barcodes array
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 (
docContent,docName,barcodeType,pages,IsAsync) - Invalid Base64 encoding in
docContent - Invalid barcode type array format
- Invalid page specification
- 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 recognition failure
Error Response Format:
{
"error": "Error message describing what went wrong"
}
Response Format Details
Important: The API always returns JSON with structured barcode data.
Response Structure:
{
"barcodes": [
{
"type": "string", // Barcode type
"text": "string", // Extracted barcode content
"page": number, // Page number (1-based)
"x": number, // X coordinate
"y": number, // Y coordinate
"width": number, // Barcode width
"height": number // Barcode height
}
]
}
Content-Type Header:
- Success:
application/json
Empty Results: If no barcodes are found, the response will contain an empty array:
{
"barcodes": []
}
Multiple Barcodes:
The API can detect multiple barcodes on the same page or across different pages. All detected barcodes are included in the barcodes array.
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
Example:
{
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"docName": "document.pdf",
"barcodeType": ["all"],
"pages": "all",
"IsAsync": true
}
Code Samples
The PDF4me Read Barcode from PDF REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:
- C#
- Java
- JavaScript
- Python
- Salesforce
- n8n
- Google Script
- AWS Lambda
Google Script Sample
Google Apps Script implementation for Google Workspace integration:
Industry Use Cases & Applications
- Finance & Banking
- Business & Enterprise
- E-commerce & Retail
- Government & Compliance
- Technology & Development
Finance & Banking Use Cases
- Invoice Processing: Extract barcode data from invoices for automated payment processing
- Financial Documents: Process financial documents with barcodes for payment processing
- Payment Processing: Extract payment information from barcodes in financial documents
- Banking Integration: Integrate barcode reading into banking applications and systems
Business & Enterprise Use Cases
- Inventory Management: Read product barcodes from PDF documents for stock tracking
- Supply Chain Management: Track products through barcode data extraction from PDF documents
- Data Integration: Integrate barcode data from PDFs into business systems
- Document Automation: Automate barcode data extraction from scanned documents
- Workflow Automation: Automate barcode data extraction in document management systems
- Business Process Automation: Automate barcode processing workflows for enterprise operations
E-commerce & Retail Use Cases
- Product Tracking: Read product barcodes from PDF documents for inventory management
- Order Processing: Extract barcode data from order documents for processing
- Quality Control: Verify product information using barcode data from PDF reports
- Supply Chain Management: Track products through barcode data extraction from PDF documents
Government & Compliance Use Cases
- Compliance Monitoring: Extract tracking codes from compliance documents
- Regulatory Documentation: Process regulatory documents with barcodes
- Government Documents: Extract barcode data from government documents
- Public Records: Process public records with barcode information
Technology & Development Use Cases
- API Integration: Integrate barcode reading into existing document processing workflows
- Batch Processing: Process large volumes of PDF documents for barcode extraction
- Data Validation: Validate barcode data extracted from PDF documents
- Form Processing: Extract barcode information from PDF forms and applications
- System Integration: Integrate barcode reading into enterprise systems and workflows
Barcode Recognition Features
Detection Capabilities
- Multi-format Support: Recognition of 1D and 2D barcodes in various formats
- Position Tracking: Accurate barcode location and positioning data with coordinates
- Page Selection: Process specific pages or entire documents using page options
Processing Features
- Batch Recognition: Extract multiple barcodes from single or multiple pages
- Type Filtering: Specify which barcode types to detect using the
barcodeTypearray - Structured Output: Returns barcode data with type, text, page, and position information