Jump to content

Recommended Posts

Posted

So, I have eleventy-billion M$ Office files (.docx, .xlsx and .pptx) in a large directory structure and I need to convert the lot to pdf (just don't ask OK....)

 

I've tried the bulk converter in Acrobat Pro but that just crashes and moans about missing plug-in installations (google says this is pretty much par for the course) and repair does nothing.

 

Is there a clever way of doing this that I have missed? Anyone got a massively brilliant script I can blag?

 

Anything to save my sanity appreciated

Andrew

Posted

$documents_path = 'C:\temp\'
$word_app = New-Object -ComObject Word.Application
# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $documents_path -Filter *.xml? | 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()
remove-item c:\temp\*.xml

 

I use this to batch convert our reports from SIMS to PDF. You could amend to use Excel etc for your means.

  • Thanks 1
Posted

Powershell.

 

# Acquire a list of DOCX files in a folder

#$File= "C:\Foofolder\foofile.docx" - UNCOMMENT IF NEEDED
$Files=GET-CHILDITEM "\\server\shares\foldername\*.DOCX"
$Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION

Foreach ($File in $Files) {
   # open a Word document, filename from the directory
   $Doc=$Word.Documents.Open($File.fullname)

   # Swap out DOCX with PDF in the Filename
   $Name=($Doc.Fullname).replace("docx","pdf")

   # Save this File as a PDF in Word 2010/2013
   $Doc.saveas([ref] $Name, [ref] 17)

   $Doc.close()
}

 

Rinse and repeat. I've used this for some big bulk runs and it's ace.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...