Clean repository and update .gitignore

- Remove build artifacts from git tracking (build/, dist/, __pycache__/, *.spec)
- Updated .gitignore to properly exclude generated files
- Added old_code/ documentation folder
- Updated sample_data.txt to show new 5-field format
- Exclude user-specific conf/app.conf from tracking
This commit is contained in:
NAME
2026-02-13 23:41:34 +02:00
parent 839828340d
commit 6a11cf3d8d
42 changed files with 2897 additions and 54569 deletions

View File

@@ -0,0 +1,303 @@
# Label Printing Workflow Analysis - Paper Size Issue
## 🔍 Problem Identified
**Issue:** Labels printing on 90cm continuous roll instead of 35mm x 25mm label
- PDF is created with correct size (35mm x 25mm)
- Printer receives PDF but ignores the page dimensions
- Printer defaults to continuous roll mode
- Label content prints at the end of a long paper strip
---
## 📊 Current Workflow Analysis
### Step 1: PDF Generation ✅ (Working)
```
print_label_pdf.py creates PDF:
- Page size: 3.5cm x 2.5cm (35mm x 25mm)
- Layout: 1/3 image + 2/3 text area
- Quality: 1200 DPI, no compression
```
**Status:** PDF dimensions are CORRECT
### Step 2: Printing via SumatraPDF ❌ (Problem)
```
SumatraPDF command:
-print-to <printer>
-silent
-print-settings noscale,landscape,fit
<pdf_file>
```
**Problem:** SumatraPDF doesn't communicate page size to printer driver
- Printer uses its default paper size setting
- If printer is set to "Continuous" or "Roll" mode → prints on long paper
- No explicit paper size passed to printer driver
---
## 🛠️ Root Cause
Thermal label printers need EXPLICIT paper size configuration:
1. **Windows Printing System Issue:**
- PDF page size ≠ Printer paper size
- Printer driver must be told: "USE THIS EXACT SIZE"
- SumatraPDF: Generic PDF viewer, doesn't set printer DEVMODE
2. **Printer Default Settings:**
- Most thermal printers default to continuous roll
- Without explicit size, they print entire "page" length
- Result: 90cm of paper with label at the end
---
## ✅ Proposed Solutions
### **Solution 1: Configure Printer Paper Size (Recommended)**
#### Manual Configuration:
1. Open **Printer Preferences** for "Labels" printer
2. Go to **Page Setup** or **Paper/Quality** tab
3. Set paper size to **Custom: 35mm x 25mm**
4. Set orientation to **Landscape**
5. Save as default
#### PowerShell Script:
```powershell
# Run the printer configuration script
.\configure_label_size.ps1
```
**Pros:**
- ✅ One-time setup
- ✅ Works with any PDF viewer
- ✅ Simplest solution
**Cons:**
- ❌ Needs manual configuration per computer
- ❌ Settings can be reset by driver updates
---
### **Solution 2: Use Win32 Print API with Explicit Size (Best Control)**
Use `print_with_size.py` module that:
- Opens printer with Win32 API
- Sets DEVMODE structure with exact dimensions:
```python
devmode.PaperSize = 256 # Custom
devmode.PaperLength = 250 # 25mm in 0.1mm units
devmode.PaperWidth = 350 # 35mm in 0.1mm units
devmode.Orientation = 2 # Landscape
```
- Prints with guaranteed size
**Implementation:**
```python
# In print_label.py, replace SumatraPDF call with:
from print_with_size import set_printer_paper_size, print_with_custom_size
# Configure printer once
set_printer_paper_size(printer_name, 35, 25)
# Then print normally
print_to_printer(printer_name, pdf_file)
```
**Pros:**
- ✅ Programmatic control
- ✅ Always sets correct size
- ✅ No manual configuration needed
**Cons:**
- ❌ More complex code
- ❌ Windows-only
- ❌ Requires pywin32
---
### **Solution 3: Use Label Template PDF (Most Reliable)**
Create a proper label template that printers recognize:
1. **Design in Label Software:**
- Use manufacturer's label design software (e.g., Zebra Designer, BarTender)
- Or use professional tool like Adobe Illustrator
- Export as PDF with embedded printer settings
2. **Template Features:**
- Embedded page size metadata
- Printer-specific settings
- Registration marks (optional)
3. **Dynamic Field Replacement:**
- Template has placeholder text: `{COMANDA}`, `{ARTICLE}`, `{SERIAL}`
- Python replaces placeholders before printing
- Or use PDF form fields
**Implementation:**
```python
# Create template with proper settings
from PyPDF2 import PdfReader, PdfWriter
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
def fill_label_template(template_path, data, output_path):
"""
Fill label template with data.
Template has proper printer settings embedded.
"""
# Read template
template = PdfReader(template_path)
# Create overlay with data
packet = io.BytesIO()
c = canvas.Canvas(packet, pagesize=(35*mm, 25*mm))
# Add text at specific coordinates
c.setFont("Helvetica-Bold", 8)
c.drawString(15*mm, 18*mm, f"Nr. Comanda: {data['comanda']}")
c.drawString(15*mm, 12*mm, f"Nr. Art.: {data['article']}")
c.drawString(15*mm, 6*mm, f"Serial No.: {data['serial']}")
c.save()
# Merge with template
overlay = PdfReader(packet)
page = template.pages[0]
page.merge_page(overlay.pages[0])
# Write output
writer = PdfWriter()
writer.add_page(page)
with open(output_path, 'wb') as f:
writer.write(f)
return output_path
```
**Pros:**
- ✅ Most reliable across different systems
- ✅ Printer recognizes format immediately
- ✅ Professional appearance
- ✅ Can include printer-specific optimizations
**Cons:**
- ❌ Requires template creation/design
- ❌ Changes need template update
---
## 🎯 Recommended Approach
**Immediate Fix (5 minutes):**
```powershell
# 1. Configure printer paper size
.\configure_label_size.ps1
# OR manually:
# - Open Printer Preferences
# - Set paper size to 35mm x 25mm
# - Set orientation to Landscape
```
**Long-term Solution (30 minutes):**
1. Create proper label template in label design software
2. Export as PDF with embedded settings
3. Use template-based printing in application
**Alternative (if above doesn't work):**
1. Integrate `print_with_size.py` module
2. Modify `print_label.py` to use Win32 API printing
3. Explicit paper size on every print job
---
## 📝 Implementation Priority
### Priority 1 (DO NOW):
1. ✅ Configure printer manually
2. ✅ Test with current code
3. ✅ Verify label prints at correct size
### Priority 2 (THIS WEEK):
1. 🔄 Create label template with proper settings
2. 🔄 Test template-based printing
3. 🔄 Update application to use template
### Priority 3 (IF NEEDED):
1. ⏳ Implement Win32 API printing
2. ⏳ Add automatic paper size detection
3. ⏳ Create printer setup wizard
---
## 🧪 Testing Steps
After implementing any solution:
1. **Test print:**
```powershell
python test_quality.py
```
2. **Verify:**
- ✓ Paper stops at 35mm (not 90cm)
- ✓ Label fills entire label area
- ✓ No blank space before/after label
- ✓ Text is readable and properly positioned
3. **Check printer:**
- ✓ Paper advance is correct
- ✓ No paper waste
- ✓ Multiple labels print consecutively
---
## 📞 Quick Fix Script
Create and run this PowerShell script to configure your printer now:
**File: `configure_label_size.ps1`**
```powershell
$printerName = "Labels"
Write-Host "Configuring printer for 35mm x 25mm labels..." -ForegroundColor Cyan
# Open printer preferences dialog for manual config
rundll32 printui.dll,PrintUIEntry /e /n "$printerName"
Write-Host ""
Write-Host "In the printer preferences window:" -ForegroundColor Yellow
Write-Host "1. Find 'Paper Size' or 'Media' settings" -ForegroundColor White
Write-Host "2. Select 'Custom' or create new size: 35mm x 25mm" -ForegroundColor White
Write-Host "3. Set orientation to: Landscape" -ForegroundColor White
Write-Host "4. Click OK to save" -ForegroundColor White
Write-Host ""
Write-Host "After configuration, test with: python test_quality.py" -ForegroundColor Green
```
Run: `.\configure_label_size.ps1`
---
## 🎓 Why This Happens
**Technical Explanation:**
Thermal label printers have two modes:
1. **Label Mode:** Prints on predefined label sizes (35mm, 50mm, etc.)
2. **Continuous Mode:** Prints on continuous roll (any length)
When you send a PDF:
- PDF says: "I'm 35mm x 25mm"
- Printer says: "I don't see a label size command, using default (continuous)"
- Result: Prints on continuous roll
**Solution:** Tell printer explicitly to use Label Mode with 35mm x 25mm size.
---
**Last Updated:** February 13, 2026
**Status:** Solution pending - user must configure printer paper size