Abbyy Finereader Python -
cmd = [ fine_cmd, input_path, f"/out:output_path", f"/fmt:output_format", "/lang:English", # Use multiple: "/lang:English,French,German" "/recognize", "/auto", # Automatic document analysis "/close" ]
def __del__(self): self.app.Quit() pythoncom.CoUninitialize() fr = FineReaderCOM() text = fr.get_recognized_text("invoice.jpg") print(text[:500]) Zonal OCR example (extract specific invoice fields) zones = [(100, 200, 400, 230), # Invoice number (100, 300, 400, 330), # Date (500, 500, 800, 800)] # Total amount invoice_data = fr.zonal_ocr("invoice.jpg", zones) print(invoice_data) Advanced: PDF Searchable Creation def create_searchable_pdf(input_pdf_path, output_pdf_path): """Convert image-only PDF to searchable PDF/A.""" fr = FineReaderCOM() doc = fr.app.CreateDocument() # Load PDF pages doc.AddImageFile(input_pdf_path, 0)
1. Introduction ABBYY FineReader is a powerful optical character recognition (OCR) software that converts scanned documents, PDFs, and images into editable and searchable formats. While FineReader has a rich GUI, it also provides automation capabilities that can be controlled via Python, enabling batch processing, workflow integration, and custom document handling. abbyy finereader python
def submit_ocr_task(self, file_path, output_format="pdf"): """Submit a file for OCR processing.""" with open(file_path, 'rb') as f: files = 'file': (Path(file_path).name, f) data = 'outputFormat': output_format, 'language': 'English', 'recognitionAccuracy': 'high', 'documentProcessingMode': 'auto' response = self.session.post( f"self.base_url/api/v1/tasks", files=files, data=data ) return response.json()['taskId']
def process_invoice(self, image_path): """Extract structured data from invoice image.""" # Extract text from zones extracted = {} for field, zone in self.zones.items(): text = self.fr.zonal_ocr(image_path, [zone])[0] extracted[field] = text.strip() # Parse line items from full text full_text = self.fr.get_recognized_text(image_path) line_items = self._extract_line_items(full_text) # Parse and clean invoice = 'number': self._clean_invoice_number(extracted['invoice_number']), 'date': self._parse_date(extracted['invoice_date']), 'due_date': self._parse_date(extracted['due_date']), 'total': self._parse_amount(extracted['total_amount']), 'vendor': extracted['vendor_name'], 'vendor_address': extracted['vendor_address'], 'line_items': line_items, 'processed_at': datetime.now().isoformat() return invoice f) data = 'outputFormat': output_format
@ocr_with_retry(max_retries=3) def robust_ocr(input_path): # Your OCR implementation pass | Limitation | Alternative | |------------|-------------| | Windows-only (COM method) | Use CLI or Server API | | License required | Tesseract (free), Google Cloud Vision | | Slow for large batches | Use FineReader Server (distributed) | | Complex layout handling | Adobe Extract API | 11. Complete Working Example # full_pipeline.py import os from pathlib import Path import json from datetime import datetime def main(): # Setup input_folder = "./input_scans" output_folder = "./ocr_results" os.makedirs(output_folder, exist_ok=True)
def _clean_invoice_number(self, raw): match = re.search(r'INV[-_]?\d5,10', raw) return match.group(0) if match else raw exist_ok=True) def _clean_invoice_number(self
def get_recognized_text(self, input_path): """Return recognized text as string without saving to file.""" doc = self.app.CreateDocument() doc.AddImageFile(input_path, 0) doc.AnalyzeLayout() doc.Recognize("English") # Extract text from all pages full_text = [] for i in range(doc.Pages.Count): full_text.append(doc.Pages[i].Text) doc.Close() return "\n\n".join(full_text)
results = [] for image in Path(input_folder).glob("*.jpg"): print(f"Processing: image.name") # OCR text = fr.get_recognized_text(str(image)) # Save text txt_path = Path(output_folder) / f"image.stem.txt" txt_path.write_text(text, encoding='utf-8') # Save metadata results.append( "file": image.name, "text_length": len(text), "timestamp": datetime.now().isoformat() )
if cache_file.exists(): with open(cache_file, 'rb') as f: return pickle.load(f)
if result.returncode == 0: print(f"OCR successful: output_path.output_format") else: print(f"Error: result.stderr")