Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

BulkWord2PDF

By: a guest on Jun 11th, 2013  |  syntax: None  |  size: 0.54 KB  |  views: 230  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Acquire a list of DOCX files in a folder
  2.  
  3. $File=”C:\Foofolder\foofile.docx"
  4. $Files=GET-CHILDITEM ‘C:\FooFolder\*.DOCX’
  5. $Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION
  6.  
  7.  
  8. Foreach ($File in $Files) {
  9.  
  10.     # open a Word document, filename from the directory
  11.  
  12.     $Doc=$Word.Documents.Open($File.fullname)
  13.  
  14.  
  15.  
  16.     # Swap out DOCX with PDF in the Filename
  17.  
  18. $Name=($Doc.Fullname).replace(“docx”,”pdf”)
  19.  
  20.  
  21.  
  22.     # Save this File as a PDF in Word 2010/2013
  23.  
  24.     $Doc.saveas([ref] $Name, [ref] 17)
  25.  
  26.     $Doc.close()
  27.  
  28. }