You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

how do I use automator to batch convert doc to pdf?

Although I thought it would be an easy thing to do I'm finding it difficult to get much info or help on this. The few scripts and instructions I have discovered on the web don't seem to work. I tried to create one with a get file and then convert word docx. It creates the pdfs but they are corrupted and can't be opened.


Any ideas anyone?

Macpro, Mac OS X (10.6.4)

Posted on May 11, 2011 12:06 AM

Reply
90 replies

May 30, 2011 3:32 PM in response to Marlinespike

@Marlinespike & @RodChristiansen:


Sorry, there is no "save as file format format PDF" command in Word 2004`s and PowerPoint`s AppleScript dictionary ....



You could try to realize it via so called "GUI Scripting"

I really do not like GUI Scripting 😐 ... but i hope this script will work for you:

(You enable GUI Scripting by enabling access for assistive devices in the Universal Access System Preferences panel -- but the first lines in the AppleScript will do this for you too)



this will work with one or more files.

Running it as a Service (as RodChristiansen showed) is a good idea.



on run {input, parameters}


--ENABLE GUI SCRIPTING

tell application "System Events"

if UI elements enabled is false then set UI elements enabled to true

end tell


--RUN THE GUISCRIPT

set pdfSavePath to POSIX path of (choose folder with prompt "Set destination folder")

repeat with x in input


tell application "Microsoft Word"


activate

open x

set theActiveDoc to the active document


tell application "System Events"

tell process "Microsoft Word"


keystroke "p" usingcommand down

repeat until exists window "Print"

end repeat

click menu button "PDF" of window "Print"

repeat until exists menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"

end repeat

click menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"

repeat until exists window "Save"

end repeat


keystroke "g" using {command down, shift down}

set value of text field 1 of sheet of window "Save" to pdfSavePath

click button "Go" of sheet of window "Save"

click button "Save" of window "Save"

end tell

end tell


closetheActiveDoc

end tell

end repeat

return input

end run


Sep 26, 2011 4:18 PM in response to Rod Christiansen

Hi!

Sorry! I did not join here for a long time. Let´s start with the current question by Ron Christiansen:


You could enter a line near the end of the AppleScript (the first one?)


[…]

end if

end tell

tell application "Finder" to delete x


end try

end repeat

[…]




or in the GUI-Script:


[…]


closetheActiveDoc

end tell

tell application "Finder" to delete x


end repeat

[…]



This would be the most easy way.


Spazek

Sep 28, 2011 3:59 AM in response to jonnie5

Maybe I did not understand (i am no native english speaker) ...

Using Automator Action to Convert ppt(x) to PDF opens PowerPoint on a Windows virtual machine version?


If so, this would be really strange and you can try to use AppleScript as well.

Use it in the way described in the example workflow above



property theList : {"ppt", "pptx"}


on run {input, parameters}

set output to {}


repeat with x in input

try

set thePPT to contents of x

tell application "Finder"

set theFilePath to container of thePPT as text


set ext to name extension of thePPT

if ext is in theList then

set theName to name of thePPT

copy length of theName to l

copy length of ext to exl


set n to l - exl - 1

copy characters 1 through n of theName as string to theFilename


set theFilename to theFilename & ".pdf"

set theOutputPath to (theFilePath & theFilename as string)

set PP to POSIX path of theOutputPath

tell application "Microsoft PowerPoint"

open thePPT

set theActivePPT to the active presentation


savetheActivePPTintheOutputPathassave as PDF

copy PP to end of output


closetheActivePPT

end tell

end if

end tell


--tell application "Finder" to delete x

end try

end repeat


--tell application "Microsoft PowerPoint" to quit


return output

end run



Spazek

Nov 8, 2011 2:18 PM in response to spazek

Spazek, this is brilliant and has saved me much time, thanks! I tried to dumb down the automator actions to the simplest steps, but Word keeps coming up the dialogue "Could not fire event." Hmmm...


I also need to convert the files to plain text and I am not familiar with AppleScript. Problem is that the files contain English and another language, so they need to be encoded with Unicode 5.1, line breaks with CR only. Could you tell me what needs to be changed in the script?


Thanks!

Nov 9, 2011 4:42 PM in response to sumtingwang

Hi sumtingwang,


Unicode 5.1 sounds as if you are using an older version of Word since the current Unicode version is Unicode 6.

But ... truly said, i am absolutly not familiar with Unicode!


To save a document as plain text you have to change following lines:


set theFilename to theFilename & ".txt"


and



save astheActiveDocfile formatformat Unicode texttext encoding 6 line ending typeline ending cr onlyfile nametheFilename


or in your case




save astheActiveDocfile formatformat Unicode texttext encoding 5 line ending typeline ending cr onlyfile nametheFilename


or maybe even



save astheActiveDocfile formatformat texttext encoding 5 line ending typeline ending cr onlyfile nametheFilename



I am not sure about the command "text encoding 5"

From AS Dictionary:

[text encoding unsigned integer] : Text encoding to use when saving out as text file



Spazek


Nov 9, 2011 5:30 PM in response to spazek

Spazek, thanks much for the reply. I did end up loading the Word libraries into Applescript editor and changing the lines you mentioned. However, after a bit more searching and fiddling with the command line utils, I found this and modified it a bit:


find . -name *.doc -exec textutil -convert txt '{}' \;


Navigate to the parent directory with the word files in Terminal--it is recursive. Took all of about 20 seconds to convert 120 files.


Thanks again!

how do I use automator to batch convert doc to pdf?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.