pptx to pdf
windows에서 PPT to pdf로 변환하기
가끔씩 사용하게 되는데, 매번 gpt 시키기 귀찮아서 기록해둔다.
linux의 경우 libreoffice cli tool 사용하면 되는데, 깨지는 것들이 있어서 windows 환경에서 ppt 작업하는게 베스트다.
Generated by GPT.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 현재 디렉토리의 PPT/PPTX를 ./pdf 폴더로 PDF 변환
$here = Get-Location
$pdfDir = Join-Path $here "pdf"
if (-not (Test-Path $pdfDir)) { New-Item -Path $pdfDir -ItemType Directory | Out-Null }
# PowerPoint COM 시작
try {
$pp = New-Object -ComObject PowerPoint.Application
$pp.Visible = -1 # msoTrue (앱 창 숨김 불가한 환경 대비: 보이도록)
$pp.DisplayAlerts = 1 # ppAlertsNone
} catch {
Write-Error "PowerPoint가 설치되어 있어야 합니다. $_"
return
}
# 대상 파일 수집 (현재 폴더만)
$files = Get-ChildItem -Path $here -File | Where-Object { $_.Extension -in ('.ppt', '.pptx') }
if (-not $files) {
Write-Host "변환할 PPT/PPTX 파일이 없습니다."
$pp.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($pp) | Out-Null
return
}
foreach ($f in $files) {
$pdfPath = Join-Path $pdfDir ($f.BaseName + ".pdf")
$pres = $null
try {
if (Test-Path $pdfPath) { Remove-Item $pdfPath -Force }
# Open(FileName, ReadOnly, Untitled, WithWindow)
# WithWindow=$false 로 프레젠테이션 창은 띄우지 않음 (앱은 표시될 수 있음)
$pres = $pp.Presentations.Open($f.FullName, $true, $false, $false)
# PDF 저장 (32 = ppSaveAsPDF)
$pres.SaveAs($pdfPath, 32)
$pres.Close()
Write-Host "완료: $($f.Name) -> $([System.IO.Path]::GetFileName($pdfPath))"
} catch {
Write-Warning "실패: $($f.Name) ($_)"
try { if ($pres) { $pres.Close() } } catch {}
} finally {
if ($pres) {
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($pres) | Out-Null
$pres = $null
}
}
}
# 정리
$pp.Quit()
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($pp) | Out-Null
This post is licensed under CC BY 4.0 by the author.