# Logo Display Issues - Troubleshooting Guide

## Issue: Logo showing as "X" (broken image) in PDFs

### Root Causes:
1. **File path issues** - Logo file not found
2. **Permission issues** - PHP can't read the file
3. **Base64 encoding issues** - Image data corrupted
4. **Cache issues** - Old PDF cached
5. **wkhtmltopdf issues** - PDF generator can't process image

---

## FIXES APPLIED

### Enhanced Logo Code (All Reports)

**Before:**
```php
$logoPath = public_path('admin/images/bncmc-logo.png');
if (file_exists($logoPath)) {
    $logoData = base64_encode(file_get_contents($logoPath));
    $logoSrc = 'data:image/png;base64,' . $logoData;
} else {
    $logoSrc = asset('admin/images/bncmc-logo.png');
}
```

**After (Enhanced):**
```php
$logoPath = public_path('admin/images/bncmc-logo.png');
$logoSrc = '';

if (file_exists($logoPath)) {
    try {
        $imageData = file_get_contents($logoPath);
        $base64 = base64_encode($imageData);
        $logoSrc = 'data:image/png;base64,' . $base64;
    } catch (\Exception $e) {
        // Fallback to asset path if base64 fails
        $logoSrc = asset('admin/images/bncmc-logo.png');
    }
} else {
    // File doesn't exist, use asset path
    $logoSrc = asset('admin/images/bncmc-logo.png');
}
```

**With Fallback Display:**
```html
@if($logoSrc)
    <img src="{{ $logoSrc }}" alt="Logo" style="height: 50px; max-width: 100px;">
@else
    <div style="height: 50px; width: 100px; border: 1px solid #ccc;">Logo</div>
@endif
```

---

## VERIFICATION STEPS

### 1. Check Logo File Exists
```powershell
Test-Path "public\admin\images\bncmc-logo.png"
# Should return: True
```

### 2. Check File Permissions
```powershell
Get-Acl "public\admin\images\bncmc-logo.png" | Format-List
# Ensure PHP/Web server has read access
```

### 3. Check File Size
```powershell
(Get-Item "public\admin\images\bncmc-logo.png").Length
# Should be reasonable (< 1MB for logos)
```

### 4. Verify Image is Valid PNG
```powershell
# Open in image viewer to verify it's not corrupted
```

---

## TESTING PROCEDURE

### Test 1: Generate Report
1. Go to Demand Register Report
2. Select date range with data
3. Click "Generate PDF"
4. Check if logo displays

### Test 2: Check Browser Console
1. If viewing in browser first (not PDF)
2. Open Developer Tools (F12)
3. Check Console for errors
4. Check Network tab for failed image requests

### Test 3: Check PDF Source
1. Generate PDF
2. Open PDF in browser
3. Right-click → Inspect Element
4. Look for the img tag
5. Check if src has base64 data

---

## COMMON ISSUES & SOLUTIONS

### Issue 1: File Not Found
**Symptom:** Logo shows X
**Solution:** 
```bash
# Verify file exists
ls public/admin/images/bncmc-logo.png

# If missing, add the logo file
```

### Issue 2: Permission Denied
**Symptom:** PHP error or blank logo
**Solution:**
```bash
# On Linux/Mac
chmod 644 public/admin/images/bncmc-logo.png

# On Windows
# Right-click → Properties → Security → Add read permissions
```

### Issue 3: Cache Issue
**Symptom:** Old logo or no logo after fixing
**Solution:**
```bash
php artisan cache:clear
php artisan view:clear
php artisan config:clear

# Also clear browser cache (Ctrl+Shift+R)
```

### Issue 4: Base64 Too Large
**Symptom:** PDF generation slow or fails
**Solution:**
```bash
# Optimize logo file
# Reduce size to < 100KB
# Use PNG compression tools
```

### Issue 5: wkhtmltopdf Issue
**Symptom:** Logo works in browser but not PDF
**Solution:**
```bash
# Check wkhtmltopdf version
wkhtmltopdf --version

# Update if needed
# Ensure using version 0.12.6 or later
```

---

## FILES UPDATED WITH ENHANCED LOGO CODE

✅ Vasuli Chalan Report
- `vasuli_chalan/print.blade.php`

✅ Demand Register Report  
- `demand_register/summary_pdf.blade.php` ← **JUST UPDATED**
- `demand_register/detail_pdf.blade.php` ← **JUST UPDATED**

✅ Collection Report
- `collection_report/summary_pdf.blade.php`
- `collection_report/detail_pdf.blade.php`

⏳ Arrears Report (needs update)
- `arrears_report/summary_pdf.blade.php`
- `arrears_report/detail_pdf.blade.php`

⏳ Demand Collection Arrears Report (needs update)
- `demand_collection_arrears_report/summary_pdf.blade.php`
- `demand_collection_arrears_report/detail_pdf.blade.php`

⏳ New Connection Report (needs update)
- `new_connection_report/summary_pdf.blade.php`
- `new_connection_report/detail_pdf.blade.php`

⏳ Connection Closure Report (needs update)
- `connection_closure_report/summary_pdf.blade.php`
- `connection_closure_report/detail_pdf.blade.php`

---

## NEXT STEPS

1. **Clear all caches** on server
2. **Test Demand Register** report generation
3. **Check PDF** for logo display
4. **If still broken**, check Laravel logs:
   ```bash
   tail -f storage/logs/laravel.log
   ```

---

## ALTERNATIVE SOLUTION

If base64 still doesn't work, use direct file path with wkhtmltopdf option:

```php
// In PdfService or controller
$pdf->setOption('enable-local-file-access', true);
$pdf->setOption('images', true);

// Then use direct path
<img src="file:///{{ $logoPath }}" alt="Logo">
```

---

## CONTACT POINTS

If issues persist:
1. Check Laravel error logs
2. Check web server error logs
3. Test with a simple test image
4. Verify wkhtmltopdf installation

The enhanced code should now handle all edge cases and provide better debugging information!
