# Label Printing Workflow - Corrected & Restored
## đ Complete Workflow
### â
Correct Process (Now Working)
```
1. File Monitoring
â
txt file changes detected (e.g., "COM-2024-002;ART-67890;SN-20260212")
â
2. Parse Data
â
Split by semicolon:
- Value 1 (Article/Comanda): "COM-2024-002"
- Value 2 (Nr. Art.): "ART-67890"
- Value 3 (Serial No.): "SN-20260212"
â
3. Load SVG Template
â
Read: conf/label_template.svg
â
4. Replace Variables in Template
â
{Article} â "COM-2024-002"
{NrArt} â "ART-67890"
{Serial} â "SN-20260212"
â
5. Convert SVG â PDF
â
CairoSVG converts to high-quality PDF @ 1200 DPI
Saves to: pdf_backup/final_label_TIMESTAMP.pdf
â
6. Print PDF
â
SumatraPDF sends to configured printer
â
7. Done! â
```
---
## đŻ Key Features
### 1. **Customizable Layout** (SVG Template)
- Location: `conf/label_template.svg`
- Users can edit this file to change:
- Position of text fields
- Font size and style
- Graphics/images
- Label dimensions
- **No code changes needed!**
### 2. **Variable Placeholders**
The template uses curly braces for variables:
- `{Article}` - First value (Nr. Comanda)
- `{NrArt}` - Second value (Nr. Art.)
- `{Serial}` - Third value (Serial No.)
User can move these anywhere in the SVG template.
### 3. **Automatic File Monitoring**
- Watches: The configured txt file
- On change: Automatically reads and prints
- No manual intervention needed
---
## đ§ What Was Fixed
### Problem 1: SVG Template Was Disabled â
**Before:** Code was using fallback PDF generation (hardcoded layout)
**Now:** SVG template is properly enabled and used
### Problem 2: Poor SVG Rendering â
**Before:** svglib was failing with many errors, causing fragmentedoutput
**Now:** CairoSVG is used first (better font/rendering support)
### Problem 3: Extra Conversion Steps â
**Before:** GhostScript was re-converting already good PDFs
**Now:** Direct SVG â PDF â Print (no extra conversions)
---
## đ Data Flow Example
### Input File Content:
```
COM-2024-002;ART-67890;SN-20260212
```
### Parsing:
```python
parts = text.split(';')
article = parts[0] # "COM-2024-002"
nr_art = parts[1] # "ART-67890"
serial = parts[2] # "SN-20260212"
```
### Template Before Replacement:
```xml
Nr. Comanda:{Article}
Nr. Art.:{NrArt}
Serial No.:{Serial}
```
### Template After Replacement:
```xml
Nr. Comanda:COM-2024-002
Nr. Art.:ART-67890
Serial No.:SN-20260212
```
### Output:
- PDF file: `pdf_backup/final_label_20260213_HHMMSS.pdf`
- Print: Sent to configured printer
- Log: Entry added to `logs/print_log_20260213.csv`
---
## đ¨ How to Customize the Label Layout
1. **Open the template:**
```
conf/label_template.svg
```
2. **Edit in any SVG editor:**
- Inkscape (free)
- Adobe Illustrator
- CorelDRAW
- Or any text editor
3. **Keep the variable placeholders:**
- `{Article}`
- `{NrArt}`
- `{Serial}`
4. **Save the file**
5. **Next print will use the new layout!**
### Example Changes:
- Move text to different positions
- Change font size in the SVG
- Add company logo
- Change colors
- Adjust spacing
---
## đ Testing the Workflow
### Test 1: Verify Template is Used
```powershell
.\venv\Scripts\python.exe label_printer_gui.py
```
Watch console output - should see:
```
Using SVG template: conf\label_template.svg
Converting SVG to PDF using CairoSVG (high quality)...
â
PDF created from SVG template: pdf_backup\final_label_...pdf
```
### Test 2: Check the Generated PDF
```powershell
# Open latest PDF to verify content
$latest = Get-ChildItem pdf_backup\*.pdf | Sort-Object LastWriteTime -Desc | Select-Object -First 1
Start-Process $latest.FullName
```
Verify you see:
- â
Three lines of text (Nr. Comanda, Nr. Art., Serial No.)
- â
Values filled in correctly
- â
Checkmark image (if template has it)
### Test 3: Print Test
Put sample data in your monitored file:
```
COM-TEST-001;ART-7777;SN-20260213
```
Should automatically print with correct values.
---
## âď¸ Configuration Files
### 1. **Label Template** (conf/label_template.svg)
- **Purpose:** Defines layout, positions, fonts
- **Editable:** Yes - by user
- **Format:** SVG (XML-based vector graphics)
### 2. **App Configuration** (conf/app.conf)
- **Purpose:** Stores GUI settings
- **Contains:**
- File path to monitor
- Selected printer
- Preview settings
### 3. **Images** (conf/*.png)
- **accepted.png:** Checkmark/approval image (embedded in template)
- **refused.png:** Rejection image (if needed)
---
## đ Complete Print Quality Settings
The system now maintains quality through:
1. **SVG Template** â Vector graphics (scalable, sharp)
2. **CairoSVG Conversion** â Renders @ 1200 DPI
3. **PDF Output** â Uncompressed, high quality
4. **Printer Configuration** â Set to 600 DPI minimum
5. **Direct Printing** â No extra conversions
---
## đ Workflow States
| Step | Status | Output |
|------|--------|--------|
| File changed | â
Working | Triggers processing |
| Parse data | â
Working | Splits by `;` |
| Load template | â
Working | Reads SVG file |
| Replace variables | â
Working | Substitutes `{...}` |
| SVGâPDF | â
Working | CairoSVG @ 1200 DPI |
| Print | â
Working | SumatraPDF direct |
---
## đ Troubleshooting
### Issue: "SVG template not found"
**Solution:** Check that `conf/label_template.svg` exists
### Issue: "CairoSVG conversion failed"
**Solution:**
```powershell
.\venv\Scripts\pip.exe install --upgrade cairosvg
```
### Issue: Wrong values printed
**Solution:** Verify data format in txt file: `value1;value2;value3`
### Issue: Printer prints blank/partial
**Solution:** Run printer configuration:
```powershell
.\configure_label_size.ps1
```
---
## đ Summary
The workflow is now **fully restored** and **working correctly**:
â
SVG template enabled for customizable layouts
â
Variable replacement working ({Article}, {NrArt}, {Serial})
â
High-quality PDF generation via CairoSVG
â
Direct printing without extra conversions
â
User can modify template without code changes
**No more hardcoded layouts!**
---
**Last Updated:** February 13, 2026
**Status:** â
Workflow Restored & Working