Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Batch convert Word files to PDFs via Pages Apps
This recent hint on automating print to PDF via Pages and AppleScript gave me the impetus to write an AppleScript for batch converting Word (or any other files that Pages can open) to PDF files (or any format that Pages can export to). Here's the script: Save the script as a droplet. Drop a bunch of Word files on it, and they will be converted to PDF files on your desktop. For converting to other formats, in the line starting with set filname to, change pdf to rtf or txt.

[robg adds: This worked as described when I tested it. Note that Pages may not be able to handle all of Word's formatting option -- this will be especially true if you're using the new page layout format available in Word 2008. In those cases, you'll get the best results by saving as a PDF directly from Word.]
    •    
  • Currently 3.43 / 5
  You rated: 3 / 5 (7 votes cast)
 
[17,398 views]  

Batch convert Word files to PDFs via Pages | 10 comments | Create New Account
Click here to return to the 'Batch convert Word files to PDFs via Pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Batch convert Word files to PDFs via Pages
Authored by: musselrock on Oct 20, '08 08:56:45AM

I wrote a script to use Word 2008 for batch converting Word files to PDFs. I found that Word 2008 does not preserve links in Word documents when converting them to PDFs. Pages, on the other hand, preserves the links nicely.

I also rewrote the Pages script to handle variable length name extensions, below.

on open filist
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
end tell
set x to the offset of "." in thename
set nuname to text 1 thru text item x of thename --remove the old name extension
tell application "Pages"
activate
set filname to (path to desktop folder as text) & nuname & "pdf"
set x to make new document with properties {path:filname}
open lvar
save document 1 in file filname
close every window saving no
end tell
end repeat
end open



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: ptone on Oct 20, '08 11:05:11AM
You can skip the creation of a new document by using a line like:

save document 1 as "SLDocumentTypePDF" in ((thePath as string) & fname & ".pdf")

[ Reply to This | # ]

Batch convert Word files to PDFs via Pages
Authored by: musselrock on Oct 20, '08 11:50:46AM

That's very good. Thank you. Where did you find this:

save document 1 as "SLDocumentTypePDF" in filname

It's not in Pages dictionary that I can find.

Script now reads:

on open filist
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
end tell
set x to the offset of "." in thename
set nuname to text 1 thru text item x of thename
set nuname to text 1 thru text item x of thename
tell application "Pages"
activate
set filname to (path to desktop folder as text) & nuname & "pdf"
open lvar
save document 1 as "SLDocumentTypePDF" in filname
close every window saving no
end tell
end repeat
end open



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: zikman on Oct 20, '08 11:16:14AM

now is it possible to do something like this, except with excel files
I have both Numbers and Excel and am looking for a way to auto-convert .xls files to PDF.



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: musselrock on Oct 20, '08 12:29:56PM

Numbers is not scriptable. Excel 2008 looks like it can do PDFs, but I can't get the syntax the way Excel wants it to be. A line something like this is needed:

save as sheet [unknown ? Syntax] file format PDF file format

Perhaps someone has already worked this out?



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: snit on Oct 20, '08 01:09:25PM

I had the need to do this recently... but instead of AppleScript I used Automator. The steps are simple:

1) Get Selected Items
2) Convert Format of Word Documents (select PDF)

I then saved it as an Finder Plug-In. Now whenever I need to do such conversions I just right-click on the set of files to be converted (control click, if you want) and select:

  More > Automator > Convert WORD to PDF

Works like a charm... but I have Word 2008... which comes with Automator actions.



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: jctull on Oct 20, '08 01:45:42PM
Ah, I like this solution.

In case you still want to do this through Pages, I made a version where the pdf is saved in the same location as the original file. Also, I made it quit Pages if Pages was not open when the script is run and leave it open otherwise.

on open filist
if application "Pages" is running then
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
set thepath to container of lvar
end tell
set x to the offset of "." in thename
set nuname to text 1 thru text item x of thename
tell application "Pages"
activate
set filname to (thepath as text) & nuname & "pdf"
open lvar
save document 1 as "SLDocumentTypePDF" in filname
close every window saving no
end tell
end repeat
else
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
set thepath to container of lvar
end tell
set x to the offset of "." in thename
set nuname to text 1 thru text item x of thename
tell application "Pages"
activate
set filname to (thepath as text) & nuname & "pdf"
open lvar
save document 1 as "SLDocumentTypePDF" in filname
close every window saving no
end tell
end repeat
tell application "Pages" to quit
end if
end open


[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: soopah256 on Jun 16, '10 04:32:35PM

Thanks for the code! It's exactly what I needed.
My files names included a "." in the filename, so I tweaked the code so that it preserves the full filename. (the *.doc extension must be present)

on open filist
if application "Pages" is running then
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
set thepath to container of lvar
end tell
set x to the offset of ".doc" in thename
set nuname to text 1 thru text item x of thename
tell application "Pages"
activate
set filname to (thepath as text) & nuname & "pdf"
open lvar
save document 1 as "SLDocumentTypePDF" in filname
close every window saving no
end tell
end repeat
else
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
set thepath to container of lvar
end tell
set x to the offset of ".doc" in thename
set nuname to text 1 thru text item x of thename
tell application "Pages"
activate
set filname to (thepath as text) & nuname & "pdf"
open lvar
save document 1 as "SLDocumentTypePDF" in filname
close every window saving no
end tell
end repeat
tell application "Pages" to quit
end if
end open



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: ejstembler on Jan 12, '09 01:44:53PM

Yes, in Microsoft Word 2008 (for Mac) I found the Automator workflow which converts a batch of Word documents into another format (including PDF).

Look for:

Convert the format of specified Word files\scg.workflow

in

/Users/{Your user name}/Documents/Microsoft User Data/Word Script Menu Items/Sample Automator Workflows/



[ Reply to This | # ]
Batch convert Word files to PDFs via Pages
Authored by: dracula77 on Jan 06, '09 08:13:44AM

How do you save a file as droplet?
Thanks.



[ Reply to This | # ]