Guest User

Untitled

a guest
Jun 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. $path = "."
  2.  
  3. # Convert all the ppt/pptx to PDF
  4.  
  5. $powerpoint_app = New-Object -ComObject PowerPoint.Application
  6. # $powerpoint_app.Visible = [Microsoft.Office.Core.MsoTriState]::msoFalse
  7.  
  8. # Search for files and convert
  9. Get-ChildItem -Path $path -Filter *.ppt? | ForEach-Object {
  10. # $ppSlideSizeOpt = [Microsoft.Office.Interop.PowerPoint.PpSlideSizeType]::ppSlideSizeOnScreen16x9
  11.  
  12. # Open the presentation
  13. echo "# Opening the '$($_.BaseName)'..."
  14. $presentation = $powerpoint_app.Presentations.Open($_.FullName)
  15. $pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
  16.  
  17. # Resize the slide size to 16x9 if it's not yet
  18. if ($presentation.PageSetup.SlideWidth -ne 960)
  19. {
  20. $presentation.PageSetup.SlideWidth = 960
  21. $presentation.PageSetup.SlideHeight = 540
  22. $presentation.Save()
  23. echo "- Set the slide size to WideScreen. Saved it."
  24. } else
  25. {
  26. echo "- The slide size WAS WideScreen."
  27. }
  28.  
  29. # Save as a PDF
  30. echo "- Saving as PDF ..."
  31. $opt = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsPDF
  32. $presentation.SaveAs($pdf_filename, $opt)
  33.  
  34. # Close the presentation object
  35. $presentation.Close()
  36.  
  37. echo "- Saved as the '$($_.BaseName).pdf'"
  38. }
  39.  
  40. sleep 3
  41. # Quit the app and release the app object
  42. $powerpoint_app.Quit()
  43. Stop-Process -name "POWERPNT"
  44. [System.Runtime.Interopservices.Marshal]::ReleaseComObject($powerpoint_app)
Add Comment
Please, Sign In to add comment