""" Generate sample document images for demonstration and testing. """ from PIL import Image, ImageDraw, ImageFont import os def create_sample_receipt(path: str): os.makedirs(os.path.dirname(path), exist_ok=True) img = Image.new("RGB", (600, 750), color="#FFFFFF") draw = ImageDraw.Draw(img) # Header draw.rectangle([(20, 20), (580, 730)], outline="#D0D5DD", width=2) draw.text((220, 40), "TECH COFFEE ROASTERS", fill="#101828") draw.text((235, 65), "123 Innovation Way, Suite 400", fill="#475467") draw.text((265, 85), "Tel: (555) 019-2834", fill="#475467") draw.line([(40, 115), (560, 115)], fill="#E4E7EC", width=1) # Metadata draw.text((40, 130), "Receipt #: TCR-2026-8942", fill="#101828") draw.text((40, 150), "Date: 2026-08-26 14:22", fill="#475467") draw.text((40, 170), "Server: Alex M.", fill="#475467") draw.line([(40, 200), (560, 200)], fill="#101828", width=2) # Table Header draw.text((40, 215), "ITEM", fill="#101828") draw.text((320, 215), "QTY", fill="#101828") draw.text((420, 215), "PRICE", fill="#101828") draw.text((500, 215), "TOTAL", fill="#101828") draw.line([(40, 240), (560, 240)], fill="#E4E7EC", width=1) # Items items = [ ("Single Origin Pour Over", "2", "$4.50", "$9.00"), ("Oat Milk Vanilla Latte", "1", "$5.75", "$5.75"), ("Almond Croissant", "2", "$4.25", "$8.50"), ("Avocado Sourdough Toast", "1", "$12.00", "$12.00"), ("Matcha Green Tea", "1", "$5.00", "$5.00"), ] y = 260 for name, qty, price, total in items: draw.text((40, y), name, fill="#344054") draw.text((330, y), qty, fill="#344054") draw.text((420, y), price, fill="#344054") draw.text((500, y), total, fill="#344054") y += 35 draw.line([(40, y + 10), (560, y + 10)], fill="#E4E7EC", width=1) y += 30 # Totals draw.text((380, y), "Subtotal:", fill="#475467") draw.text((500, y), "$40.25", fill="#101828") y += 25 draw.text((380, y), "Tax (8.25%):", fill="#475467") draw.text((500, y), "$3.32", fill="#101828") y += 25 draw.text((380, y), "Total Due:", fill="#101828") draw.text((500, y), "$43.57", fill="#101828") draw.line([(40, y + 40), (560, y + 40)], fill="#101828", width=2) y += 60 draw.text((200, y), "Thank you for your visit!", fill="#475467") draw.text((180, y + 25), "Scan QR code to join our rewards program", fill="#98A2B3") img.save(path) print(f"Generated sample receipt at: {path}") def create_sample_table_doc(path: str): os.makedirs(os.path.dirname(path), exist_ok=True) img = Image.new("RGB", (700, 500), color="#FFFFFF") draw = ImageDraw.Draw(img) draw.rectangle([(20, 20), (680, 480)], outline="#E4E7EC", width=2) draw.text((40, 40), "QUARTERLY PERFORMANCE REPORT 2026", fill="#101828") draw.text((40, 65), "Department: AI Research & Systems", fill="#475467") # Draw table table_top = 110 draw.rectangle([(40, table_top), (660, table_top + 40)], fill="#F8F9FA", outline="#D0D5DD") draw.text((50, table_top + 12), "Model Name", fill="#101828") draw.text((220, table_top + 12), "Throughput (t/s)", fill="#101828") draw.text((380, table_top + 12), "Accuracy (%)", fill="#101828") draw.text((520, table_top + 12), "Latency (ms)", fill="#101828") rows = [ ("DeepSeek-OCR", "142.5", "96.8%", "18.2"), ("Qwen3-VL", "118.0", "97.4%", "24.1"), ("PP-StructureV3", "88.4", "94.9%", "31.0"), ("NuExtract3", "130.2", "96.1%", "21.5"), ("PP-OCRv5", "210.6", "93.8%", "11.4"), ("olmOCR", "95.7", "98.2%", "29.8"), ] curr_y = table_top + 40 for name, tp, acc, lat in rows: draw.rectangle([(40, curr_y), (660, curr_y + 35)], outline="#E4E7EC") draw.text((50, curr_y + 10), name, fill="#344054") draw.text((220, curr_y + 10), tp, fill="#344054") draw.text((380, curr_y + 10), acc, fill="#344054") draw.text((520, curr_y + 10), lat, fill="#344054") curr_y += 35 draw.text((40, curr_y + 30), "Summary: All models achieved target latency within SLA thresholds.", fill="#475467") img.save(path) print(f"Generated sample table doc at: {path}") if __name__ == "__main__": create_sample_receipt("d:/OCR/sample_data/sample_receipt.png") create_sample_table_doc("d:/OCR/sample_data/sample_table.png")