# 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 -silent -print-settings noscale,landscape,fit ``` **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