Basic Powershell - batch convert Word Docx to PDF -


i trying use powershell batch conversion of word docx pdf - using script found on site: http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/24/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell.aspx

# acquire list of docx files in folder $files=get-childitem "c:\docx2pdf\*.docx" $word=new-object –comobject word.application  foreach ($file in $files) {     # open word document, filename directory     $doc=$word.documents.open($file.fullname)      # swap out docx pdf in filename     $name=($doc.fullname).replace("docx","pdf")      # save file pdf in word 2010/2013     $doc.saveas([ref] $name, [ref] 17)       $doc.close() } 

and keep on getting error , can't figure out why:

ps c:\docx2pdf> .\docx2pdf.ps1 exception calling "saveas" "16" argument(s): "command failed" @ c:\docx2pdf\docx2pdf.ps1:13 char:13 +     $doc.saveas <<<< ([ref] $name, [ref] 17)     + categoryinfo          : notspecified: (:) [], methodinvocationexception     + fullyqualifiederrorid : dotnetmethodexception 

any ideas?

also - how need change convert doc (not docx) files, use local files (files in same location script location)?

sorry - never done powershell scripting...

this work doc docx files.

$documents_path = 'c:\doc2pdf'  $word_app = new-object -comobject word.application  # filter find .doc .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() 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -