# render_pdf.ps1 — 한컴 COM 으로 .hwpx → .pdf 렌더 (검증용)
# 사용: powershell -File render_pdf.ps1 <input.hwpx> <output.pdf>
param([Parameter(Mandatory=$true)][string]$In,[Parameter(Mandatory=$true)][string]$Out)
$ErrorActionPreference='Stop'
$In=(Resolve-Path $In).Path
$h=New-Object -ComObject "HWPFrame.HwpObject"
try { $h.RegisterModule("FilePathCheckDLL","FilePathCheckerModule") | Out-Null } catch {}
try { $h.RegisterModule("FilePathCheckerDLL","FilePathCheckerModule") | Out-Null } catch {}
$null=$h.Open($In,"HWPX","")
# PDF 내보내기
try {
  $h.SaveAs($Out,"PDF","") | Out-Null
} catch {
  # 대체: HAction FileSaveAsPdf
  $pset=$h.HParameterSet.HFileOpenSave
  $h.HAction.GetDefault("FileSaveAsPdf",$pset.HSet) | Out-Null
  $pset.filename=$Out; $pset.Format="PDF"
  $h.HAction.Execute("FileSaveAsPdf",$pset.HSet) | Out-Null
}
$h.Clear(1) | Out-Null
$h.Quit() | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($h) | Out-Null
if (Test-Path $Out) { "OK: $Out ($((Get-Item $Out).Length) bytes)" } else { "FAIL: no PDF produced" }
