Skip to content

Instantly share code, notes, and snippets.

@stevehansen
Created February 10, 2021 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevehansen/8590e4c8456dab81cab772221efe4520 to your computer and use it in GitHub Desktop.
Save stevehansen/8590e4c8456dab81cab772221efe4520 to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/a/16537996/295296
$documents_path = 'c:\doc2pdf'
$word_app = New-Object -ComObject Word.Application
# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object {
$document = $word_app.Documents.Open($_.FullName)
$pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
$document.SaveAs([ref] $pdf_filename, [ref] 17)
$document.Close()
}
$word_app.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment