# 🖨️ CARA MENGONVERT KE PDF - Panduan Lengkap

## ✅ OPSI 1: CETAK LANGSUNG DARI BROWSER (RECOMMENDED)

### Langkah-langkah:

1. **Buka file HTML:**
   ```bash
   # Di browser (Chrome/Edge/Firefox/Safari)
   http://187.77.112.225:8000/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.html
   
   # Atau buka lokal
   /root/.openclaw/workspace/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.html
   ```

2. **Tekan shortcut print:**
   - **Windows/Linux:** `Ctrl + P`
   - **Mac:** `Cmd + P`

3. **Setting di Print Dialog:**
   - **Destination:** Save as PDF
   - **Paper size:** A4
   - **Margins:** Default (atau Custom: Top/Bottom 10mm, Left/Right 10mm)
   - **Scale:** 100%
   - **Options:**
     - ☑️ Background graphics (untuk warna)
     - ☑️ Headers and footers (jika perlu header/footer halaman)
     - ❌ Printing headers & footers (disable jika tidak perlu)

4. **Save/Print** → Pilih lokasi save → Beri nama file PDF

---

## ✅ OPSI 2: FILE PRINTABLE SUDAH DISEDIAKAN

File khusus untuk cetak sudah tersedia:
- **Lokasi:** `/root/.openclaw/workspace/daily_brief/ANALISA_KETAHANAN_PANGAN_2026_PRINTABLE.html`
- **Fitur:** Styling khusus untuk print (break-inside: avoid, proper margins, etc.)

Cara sama dengan opsi 1, tapi buka file _PRINTABLE.html terlebih dahulu.

---

## ✅ OPSI 3: CONVERT PROGRAMMATICALLY (Advanced)

### Method A: Menggunakan wkhtmltopdf

```bash
# Install wkhtmltopdf (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install -y wkhtmltopdf

# Convert HTML to PDF
wkhtmltopdf --page-size A4 \
    --margin-top 10mm \
    --margin-right 10mm \
    --margin-bottom 10mm \
    --margin-left 10mm \
    /root/.openclaw/workspace/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.html \
    /root/.openclaw/workspace/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.pdf

echo "✅ PDF created!"
```

### Method B: Menggunakan Python + Selenium

```python
#!/usr/bin/env python3
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

driver = webdriver.Chrome(options=chrome_options)

html_file = "/root/.openclaw/workspace/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.html"
output_pdf = "/root/.openclaw/workspace/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.pdf"

try:
    driver.get(f"file://{html_file}")
    time.sleep(2)  # Wait for page load
    
    driver.execute_cdp_cmd("Page.printToPDF", {
        "printBackground": True,
        "paperWidth": 8.27,  # A4 width in inches
        "paperHeight": 11.69,  # A4 height in inches
        "marginTop": 0.4,  # 10mm ≈ 0.4 inch
        "marginBottom": 0.4,
        "marginLeft": 0.4,
        "marginRight": 0.4
    })
    
    driver.save_page(output_pdf)
    print("✅ PDF berhasil dibuat!")
except Exception as e:
    print(f"❌ Error: {e}")
finally:
    driver.quit()
```

Install prerequisites:
```bash
pip install selenium webdriver-manager
```

---

## ✅ OPSI 4: Command Line (Quick & Simple)

```bash
cd /root/.openclaw/workspace/daily_brief/

# Cek apakah ada printer tool yang terinstall
which chromium-browser || which google-chrome-stable || echo "No headless browser found"

# Jika ada, gunakan command ini (contoh):
chromium-browser --headless --print-to-pdf="ANALISA_KETAHANAN_PANGAN_2026.pdf" "http://187.77.112.225:8000/daily_brief/ANALISA_KETAHANAN_PANGAN_2026.html"

echo "✅ Done! File saved at: $(pwd)/ANALISA_KETAHANAN_PANGAN_2026.pdf"
```

---

## 📋 CHECKLIST SETELAH KONVERSI

Setelah membuat PDF, pastikan:

- [ ] Tampilan font terbaca dengan jelas
- [ ] Tabel tidak terpotong di tengah
- [ ] Header dan footer konsisten di setiap halaman
- [ ] Gambar/grafik tampil utuh
- [ ] Warna background tetap muncul (gradient sections)
- [ ] Semua referensi link tidak terputus
- [ ] Ukuran file tidak terlalu besar (>5MB mungkin perlu kompres)

---

## 🔧 Troubleshooting

### Problem: Font kecil saat dicetak
**Solution:** Gunakan CSS @media print atau set zoom 110-120% sebelum print

### Problem: Halaman terpotong
**Solution:** 
- Turunkan scale ke 90-95%
- Perbaiki pagination dengan `<div style="page-break-after: always;"></div>`

### Problem: Link tidak bisa diklik di PDF
**Solution:** Aktifkan "Link annotations" di print dialog

### Problem: Background hilang
**Solution:** Centang "Background graphics" di print options

---

## 💡 Tips untuk Hasil Terbaik

1. **Gunakan Chrome/Edge** untuk hasil paling konsisten
2. **Preview dulu** di print dialog sebelum save
3. **Test di printer fisik** untuk cek warna akurat
4. **Kompres PDF** jika terlalu besar (gunakan smallpdf.com atau tools online)
5. **Password protect** jika dokumen sensitif

---

## 📞 Kontak Support

Jika ada masalah dalam proses konversi, silakan hubungi administrator server atau check dokumentasi teknis lebih lanjut.

---

*Panduan ini terakhir diupdate: April 15, 2026*
