?
Solved

automating MS Word 2010 -> PDF

Posted on 2014-10-20
3
Medium Priority
?
400 Views
Last Modified: 2014-10-21
I understand that it is possible to have a PowerShell script automate MS Word to read an MS Word document from a folder and save it out as a PDF document (same name, different extension) without bringing up a user GUI (in order to run on a server).

We have a need to run a script like this via the scheduler (once / minute or in a loop) to convert MS Word documents (*.doc, *.docx) to PDF (any relatively current version) on a Windows 2008 R2 (64-bit) server image.

Does anyone have the time to provide a script that can do this?  The goal is something that we can have going unattended and is reasonably immune to "hanging".
0
Comment
Question by:klamerus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 2000 total points
ID: 40392813
Use this powershell script from Scripting Guy!
http://blogs.technet.com/b/heyscriptingguy/archive/2008/11/12/how-can-i-convert-word-files-to-pdf-files.aspx

$wdFormatPDF = 17
$word = New-Object -ComObject word.application
$word.visible = $false
$folderpath = "c:\folderpath\*"
$fileTypes = "*.docx","*doc"
Get-ChildItem -path $folderpath -include $fileTypes |
foreach-object `
{
 $path =  ($_.fullname).substring(0,($_.FullName).lastindexOf("."))
 "Converting $path to pdf ..."
 $doc = $word.documents.open($_.fullname)
 $doc.saveas([ref] $path, [ref]$wdFormatPDF)
 $doc.close()
}
$word.Quit()

Open in new window


Then set it up as a scheduled task on your server that will run every 5 minutes. You will need to have word installed on the server as well.

You will also need to take a look here (this is from the comments on Scripting Guy! blog)
Summary of the 'Ogawa Hack': create a desktop folder for the system profile, as either

C:\Windows\SysWOW64\config\systemprofile\Desktop, or

C:\Windows\System32\config\systemprofile\Desktop

...depending on whether you have 64-bit Windows.

Also, the folder needs write permission for whatever user is "driving" Office.
https://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64?forum=innovateonoffice
0
 
LVL 1

Author Closing Comment

by:klamerus
ID: 40395248
This works great on my desktop (which is fine at this point).

Now I have to move on and get PPT to work.  Then onto getting these to run on a server.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40395269
Function to convert PPT files to PDF
http://pshscripts.blogspot.co.uk/2012/11/convert-pptxtopdfps1.html


Script to perform function from Thomas Lee's blog
http://tfl09.blogspot.com/2012/11/saving-powerpoint-slides-to-pdf-with.html
    $ipath = "E:\SkyDrive\PowerShell V3 Geek Week\"

    Foreach ($ifile in $(ls $ipath -Filter "*.pptx")) {
      # Build name of output file
      $pathname = split-path $ifile
      $filename = split-path $ifile -leaf
      $file     = $filename.split(".")[0]
      $ofile    = $pathname + $file + ".pdf"

      # Convert _this_ file to PDF
       Convert-PptxToPDF -ifile $ifile -OFile $ofile
    }

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question