# Aumentum LRS Multi-Page PDF Viewer
## Complete Installation Guide for Windows Server 2012 / Legacy Edge

---

## 📦 Package Contents

You have **6 files** to create:

1. `manifest.json` - Extension configuration
2. `popup.html` - Extension popup UI
3. `popup.js` - Popup logic
4. `content.js` - Runs on LRS pages
5. `background.html` - Background page
6. `setup_extension.bat` - Auto-setup script (optional)

Plus icons folder with 5 icon files.

---

## 🚀 Quick Installation (5 Steps)

### Step 1: Run Setup Script

1. Create a file called `setup_extension.bat`
2. Copy the batch script content into it
3. Double-click to run
4. Creates folder: `C:\AumentumExtension`

### Step 2: Create All Files

Create these files in `C:\AumentumExtension\`:

**File: manifest.json**
```json
{
  "name": "Aumentum LRS PDF Viewer",
  "version": "2.0.0",
  "manifest_version": 2,
  "minimum_edge_version": "38.14393.0.0",
  "description": "View LRS documents as multi-page PDFs",
  "author": "Aumentum Integration",
  "permissions": [
    "activeTab",
    "storage",
    "tabs",
    "contextMenus",
    "http://localhost:8001/*",
    "http://10.10.10.3:8001/*",
    "http://10.10.10.3:8080/*",
    "http://*/*"
  ],
  "background": {
    "page": "background.html",
    "persistent": true
  },
  "content_scripts": [
    {
      "matches": [
        "http://10.10.10.3:8080/lrswa/*",
        "http://*/lrswa/*"
      ],
      "js": ["content.js"],
      "run_at": "document_end"
    }
  ],
  "browser_action": {
    "default_icon": {
      "20": "icons/icon20.png",
      "40": "icons/icon40.png"
    },
    "default_title": "Aumentum LRS PDF Viewer",
    "default_popup": "popup.html"
  },
  "icons": {
    "16": "icons/icon16.png",
    "48": "icons/icon48.png",
    "128": "icons/icon128.png"
  }
}
```

Copy `popup.html`, `popup.js`, `content.js`, and `background.html` from the complete code artifact above.

### Step 3: Create Icons

**Option A: Let setup script create them**
- Run `setup_extension.bat`
- Choose "Y" when asked about icons

**Option B: Use any PNG image**
- Copy any PNG file 5 times
- Rename to: `icon16.png`, `icon20.png`, `icon40.png`, `icon48.png`, `icon128.png`
- Place in `C:\AumentumExtension\icons\`

### Step 4: Enable Extensions in Edge

1. Open **Microsoft Edge** (Legacy)
2. Type in address bar: `about:flags`
3. Scroll to find: **"Enable extension developer features"**
4. Check the box
5. **Restart Edge** (important!)

### Step 5: Load Extension

1. Open Edge
2. Click **More (...)** menu (top-right)
3. Click **Extensions**
4. Click **Load extension** button
5. Browse to `C:\AumentumExtension`
6. Click **Select Folder**
7. Extension should appear: "Aumentum LRS PDF Viewer"

---

## ✅ Verification

### Test 1: Extension Loaded

1. Edge → More (...) → Extensions
2. See "Aumentum LRS PDF Viewer" ✅
3. Status shows "On" ✅

### Test 2: Navigate to Document

1. Open: `http://10.10.10.3:8080/lrswa/welcome.do`
2. Search for document (e.g., BP703)
3. Click through to: `#detail:SourceDocument:10000000000188`
4. Wait 2-3 seconds
5. **"📄 View Multi-Page PDF"** button appears ✅

### Test 3: Click Extension Icon

1. Click extension icon in Edge toolbar
2. Should show: "Document detected! Loading..."
3. Metadata displays (page count, doc number)
4. **"View PDF"** button enabled ✅

### Test 4: Generate PDF

1. Click **"View PDF"** button
2. New tab opens
3. Multi-page PDF displays ✅
4. Page count matches expected ✅

---

## 📂 Final Directory Structure

```
C:\AumentumExtension\
├── manifest.json
├── popup.html
├── popup.js
├── content.js
├── background.html
└── icons\
    ├── icon16.png
    ├── icon20.png
    ├── icon40.png
    ├── icon48.png
    └── icon128.png
```

---

## 🔧 Configuration

### Change API URL

**Edit popup.js (line 10):**
```javascript
var API_BASE_URL = 'http://localhost:8001';  // Change this
```

**Edit content.js (line 10):**
```javascript
var API_BASE_URL = 'http://localhost:8001';  // Change this
```

### Change LRS Server

**Edit manifest.json:**
```json
"content_scripts": [
  {
    "matches": [
      "http://YOUR_SERVER:8080/lrswa/*"
    ]
  }
]
```

---

## 🐛 Troubleshooting

### Problem: Extension Not Loading

**Solution:**
1. Check `about:flags` - Developer features enabled?
2. Restart Edge completely
3. Verify all files in correct folder
4. Check manifest.json for syntax errors

### Problem: Button Not Appearing

**Solution:**
1. Press F12 → Console
2. Should see: "Aumentum LRS Extension loaded"
3. Wait 2-3 seconds (auto-detect runs every 2 sec)
4. Refresh LRS page
5. Check you're on correct URL pattern: `#detail:SourceDocument:`

### Problem: "Cannot connect to API"

**Solution:**
```cmd
REM Check if API is running
netstat -ano | findstr :8001

REM Test API
curl http://localhost:8001/health

REM Start API
cd C:\path\to\api
python multipage_pdf_api.py
```

### Problem: Popup Shows "Cannot access tab URL"

**Solution:**
- This is a security limitation in Legacy Edge
- **Use the in-page button instead** (automatically added)
- Or use manual lookup (enter Document ID)

### Problem: PDF Not Opening

**Solution:**
1. Check popup blocker (allow for 10.10.10.3)
2. Try right-click → Open in new window
3. Check API logs for errors
4. Verify document exists: `http://localhost:8001/documents/id/10000000000188/metadata`

---

## 🎯 Usage Methods

### Method 1: Auto-Added Button (Recommended)
- Navigate to document page
- Button appears automatically
- Click **"📄 View Multi-Page PDF"**

### Method 2: Extension Icon
- Click extension icon in toolbar
- Auto-detects document
- Click **"View PDF"**

### Method 3: Manual Lookup
- Click extension icon
- Enter Document ID manually
- Click **"Search Document"**
- Click **"View PDF"**

### Method 4: Context Menu
- Right-click on document page
- Select **"View as Multi-Page PDF"**

---

## 📊 Features

- ✅ Auto-detect document from URL
- ✅ Add button to LRS pages automatically
- ✅ Show document metadata (page count, etc.)
- ✅ Generate multi-page PDF (merge all images)
- ✅ Open in new tab
- ✅ Manual document ID lookup
- ✅ Right-click context menu
- ✅ Works with documents of any page count (1-1000+)

---

## 🔒 Security & Privacy

- Extension only runs on LRS pages
- No data sent to external servers
- All processing via your internal API
- No tracking or analytics
- Source code visible (can audit)

---

## 💡 Tips

1. **Bookmark frequently used documents** - Click extension, copy URL
2. **Use keyboard shortcut** - Right-click → View PDF (faster)
3. **Check console for errors** - F12 → Console tab
4. **Reload extension after changes** - Extensions page → Reload button
5. **Clear cache if stuck** - Edge settings → Clear browsing data

---

## 📞 Support Checklist

If something doesn't work:

- [ ] Python API running? (`http://localhost:8001/health`)
- [ ] Extension enabled? (Edge → Extensions)
- [ ] Developer features enabled? (`about:flags`)
- [ ] On correct URL? (Contains `#detail:SourceDocument:`)
- [ ] Wait 2-3 seconds? (Auto-detect polls)
- [ ] Check console? (F12 → Console tab)
- [ ] Icons exist? (Check icons folder)
- [ ] manifest.json valid? (No syntax errors)

---

## 🎉 Success Indicators

When working correctly:

1. ✅ Extension visible in Extensions page
2. ✅ Console: "Aumentum LRS Extension loaded"
3. ✅ Button appears on document pages
4. ✅ Extension icon clickable
5. ✅ Metadata displays correctly
6. ✅ PDF opens in new tab
7. ✅ All pages visible in PDF (matches page_count)

---

## 📝 Version History

**v2.0.0** - Legacy Edge Support
- Compatible with Windows Server 2012
- Uses manifest v2
- ES5 JavaScript (no ES6)
- XMLHttpRequest (no fetch)
- Background HTML page

---

## 🚀 You're All Set!

Your extension should now:
1. Auto-detect LRS documents
2. Add button to pages
3. Generate multi-page PDFs
4. Open in new tabs

**Enjoy your multi-page PDF viewer!** 🎊