[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$OutFile, [switch]$Force ) $ErrorActionPreference = 'Stop' $resolved = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path $extension = [IO.Path]::GetExtension($resolved).ToLowerInvariant() if ($extension -notin @('.pptx', '.pptm', '.ppt')) { throw 'Поддерживаются файлы .pptx, .pptm и .ppt' } if (-not $OutFile) { $outDir = Join-Path (Get-Location) 'notes' $OutFile = Join-Path $outDir ([IO.Path]::GetFileNameWithoutExtension($resolved) + '_notes.md') } $target = [IO.Path]::GetFullPath($OutFile) $format = [IO.Path]::GetExtension($target).ToLowerInvariant() if ($format -notin @('.md', '.txt', '.csv')) { throw 'Укажите расширение .md, .txt или .csv для OutFile' } if ((Test-Path -LiteralPath $target) -and -not $Force) { throw "Файл уже существует: $target. Добавьте -Force." } $parent = [IO.Path]::GetDirectoryName($target) if ($parent -and -not (Test-Path -LiteralPath $parent)) { New-Item -ItemType Directory -Path $parent -Force | Out-Null } $powerPoint = $null $presentation = $null try { try { $powerPoint = New-Object -ComObject PowerPoint.Application } catch { throw 'PowerPoint не найден. Установите настольный Microsoft PowerPoint.' } $presentation = $powerPoint.Presentations.Open($resolved, $true, $false, $false) $rows = foreach ($slide in $presentation.Slides) { $title = '' try { if ($slide.Shapes.Title) { $title = [string]$slide.Shapes.Title.TextFrame.TextRange.Text } } catch { $title = '' } $texts = New-Object System.Collections.Generic.List[string] foreach ($shape in $slide.NotesPage.Shapes) { try { if ($shape.HasTextFrame -eq -1 -and $shape.TextFrame.HasText -eq -1) { $value = [string]$shape.TextFrame.TextRange.Text if ($value.Trim()) { $texts.Add($value.Trim()) } } } catch { continue } } [pscustomobject]@{ Slide = $slide.SlideIndex Title = ($title -replace '\s+', ' ').Trim() Notes = ($texts -join [Environment]::NewLine).Trim() } } if ($format -eq '.csv') { $rows | Export-Csv -LiteralPath $target -NoTypeInformation -Encoding UTF8 } else { $lines = New-Object System.Collections.Generic.List[string] if ($format -eq '.md') { $lines.Add("# Заметки: $([IO.Path]::GetFileName($resolved))") } else { $lines.Add("Заметки: $([IO.Path]::GetFileName($resolved))") } foreach ($row in $rows) { $lines.Add('') if ($format -eq '.md') { $lines.Add("## Слайд $($row.Slide): $($row.Title)") } else { $lines.Add("=== Слайд $($row.Slide): $($row.Title) ===") } $lines.Add('') if ($row.Notes) { foreach ($line in ($row.Notes -split "`r?`n")) { $lines.Add($line) } } else { $lines.Add('Заметок нет.') } } Set-Content -LiteralPath $target -Value $lines -Encoding UTF8 } Write-Host "Готово: $target" } finally { if ($presentation) { $presentation.Close() } if ($powerPoint) { $powerPoint.Quit() } if ($presentation) { [void][Runtime.InteropServices.Marshal]::ReleaseComObject($presentation) } if ($powerPoint) { [void][Runtime.InteropServices.Marshal]::ReleaseComObject($powerPoint) } [GC]::Collect() }