jacobinwwey_obsidian-NotEMD/scripts/lib/powerpoint-render-pptx.ps1
2026-07-04 13:57:21 +08:00

35 lines
997 B
PowerShell

param(
[Parameter(Mandatory = $true)][string]$PptxPath,
[Parameter(Mandatory = $true)][string]$OutputDirectory,
[Parameter(Mandatory = $true)][int]$Width,
[Parameter(Mandatory = $true)][int]$Height
)
$ErrorActionPreference = 'Stop'
if (Test-Path $OutputDirectory) {
Remove-Item -Recurse -Force $OutputDirectory
}
New-Item -ItemType Directory -Path $OutputDirectory | Out-Null
$powerPoint = $null
$presentation = $null
try {
$powerPoint = New-Object -ComObject PowerPoint.Application
$powerPoint.Visible = -1
$presentation = $powerPoint.Presentations.Open($PptxPath)
$slideCount = $presentation.Slides.Count
$presentation.Export($OutputDirectory, 'PNG', $Width, $Height)
[pscustomobject]@{
slideCount = $slideCount
outputDirectory = $OutputDirectory
} | ConvertTo-Json -Compress
} finally {
if ($presentation -ne $null) {
$presentation.Close()
}
if ($powerPoint -ne $null) {
$powerPoint.Quit()
}
}