| Mám dost prezentací a nechce se mi to pokaždé ručně exportovat. Tak jsem si na to napsal scriptík, který vyexportuje PPTX prezentaci do PDF souboru. Druhý skript vytiskne PPTX do XPS. Nemyslím, že to potřebuje další komenty, pokud si to chcete upravit, všechno ostatní už vygůglujete podle toho zdrojáku.
Podstatné na tom kódu jsou různé hodnoty a typy, které se hůře hledají a, metoda volání COM pomocí psobject.BaseObject a uklízení paměti pomocí ReleaseComObject().
function Save-PptAs ([string] $pptFile, [string] $saveAs)
{
$ppt = New-Object -ComObject PowerPoint.Application
# FileName, ReadOnly, Untitled, WithWindow
$withWindow = [Microsoft.Office.Core.MsoTriState]::msoFalse
$slideDeck = $ppt.Presentations.Open($pptFile, [Microsoft.Office.Core.MsoTriState]::msoTrue, [Microsoft.Office.Core.MsoTriState]::msoTrue, $withWindow)
Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint
$saveOptions = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::"ppSaveAs$saveAs"
$outFile = [System.IO.Path]::ChangeExtension($pptFile, $saveAs.ToLower())
if (Test-Path $outFile) { Remove-Item $outFile -Force }
$slideDeck.SaveAs($outFile, $saveOptions)
$slideDeck.Close()
[void] [System.Runtime.Interopservices.Marshal]::ReleaseComObject($slideDeck)
$ppt.Quit()
[void] [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ppt)
}
function Print-PptAsXPS ([string] $pptFile, [string] $printAs, [string] $printHow)
{
$ppt = New-Object -ComObject PowerPoint.Application
# FileName, ReadOnly, Untitled, WithWindow
$withWindow = [Microsoft.Office.Core.MsoTriState]::msoFalse
$slideDeck = $ppt.Presentations.Open($pptFile, [Microsoft.Office.Core.MsoTriState]::msoTrue, [Microsoft.Office.Core.MsoTriState]::msoTrue, $withWindow)
Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint
$slideDeck.PrintOptions.OutputType = [Microsoft.Office.Interop.PowerPoint.PpPrintOutputType]::"ppPrintOutput$printAs"
Add-Type -AssemblyName Office
$slideDeck.PrintOptions.FitToPage = [Microsoft.Office.Core.MsoTriState]::msoTrue
$slideDeck.PrintOptions.HighQuality = [Microsoft.Office.Core.MsoTriState]::msoTrue
$slideDeck.PrintOptions.NumberOfCopies = 1
$slideDeck.PrintOptions.RangeType = [Microsoft.Office.Interop.PowerPoint.PpPrintRangeType]::ppPrintAll
$slideDeck.PrintOptions.ActivePrinter = "Microsoft XPS Document Writer";
# we must do it synchronously in order to wait before .Close() and .Quit()
$slideDeck.PrintOptions.PrintInBackground = [Microsoft.Office.Core.MsoTriState]::msoFalse
$slideDeck.PrintOptions.FrameSlides = [Microsoft.Office.Core.MsoTriState]::msoTrue
$slideDeck.PrintOptions.PrintColorType = [Microsoft.Office.Interop.PowerPoint.PpPrintColorType]::"ppPrint$printHow"
$outFile = [System.IO.Path]::ChangeExtension($pptFile, 'xps')
if (Test-Path $outFile) { Remove-Item $outFile -Force }
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo] 'en-US'
[string[]] $paramNames = @('PrintToFile', 'Collate')
[object[]] $paramValues = @($outFile, [Microsoft.Office.Core.MsoTriState]::msoTrue)
[void] $slideDeck.psobject.BaseObject.GetType().InvokeMember(
'PrintOut',
[Reflection.BindingFlags]::InvokeMethod,
$null,
$slideDeck.psobject.BaseObject,
$paramValues,
$null, # ParameterModifiers
([System.Globalization.CultureInfo] 'en-US'),
$paramNames
)
$slideDeck.Close()
[void] [System.Runtime.Interopservices.Marshal]::ReleaseComObject($slideDeck)
$ppt.Quit()
[void] [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ppt)
}
Tak užívejte :-) |