Of course.
Copy/paste the following AppleScript into your Script Editor (launchpad : Other : Script Editor). Click the hammer icon to compile it (multi-color code). When you click the black arrow button to run it, there will be a prompt to choose your file (Pages or Word), and it will be written back to the same location with a PDF extension.
I would save the Script once as AppleScript source (plain text) using File Format: Text. Then option+Save As with File Format: your choice of script, script bundle, or application) to your Desktop.
Code:
-- PDFbest.applescript
-- Export Pages v5.6, v5.6.1, or later document as PDF Best
-- v1.2, added support for selection of Word documents
-- VikingOSX, Jan. 2016, Apple Support Community
use scripting additions
-- Allow selection of all Pages, and MS Word document formats
property valid_document : {"com.apple.iwork.pages.sffpages", "com.apple.iwork.pages.pages", "org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"}
property default_loc : ((path to desktop) as text) as alias
try
set theFile to (choose fileof typevalid_documentwith prompt "Choose a Pages or Word document:" showing package contentsnodefault locationdefault_loc without invisibles)
if result = {button returned:"Cancel"} then error number -128
on error errmsgnumbererrnbr
my error_handler(errnbr, errmsg)
return
end try
tell application "System Events"
set pf_info to package folder of theFile as boolean
set name_ext to name extension of theFile
end tell
-- use original document path and name, but change extension
if false is in pf_info then
if name_ext contains "pages" then
set exportDocument to text 1 thru -6 of (theFile as text) & "pdf"
else if name_ext contains "docx" then
set exportDocument to text 1 thru -5 of (theFile as text) & "pdf"
else if name_ext contains "doc" then
set exportDocument to text 1 thru -4 of (theFile as text) & "pdf"
end if
else
-- Pages package folders name extension ends in ':'
set exportDocument to text 1 thru -7 of (theFile as text) & "pdf"
end if
tell application "Pages"
activate
try
with timeout of 1200 seconds
set mydoc to open theFile
exportmydoctofileexportDocumentasPDFwith properties {image quality:Best}
end timeout
closemydocsavingno
on error errmsg number errnbr
my error_handler(errnbr, errmsg)
tell application "Pages" to if it is running then quit
end try
end tell
tell application "Finder"
if existsfileexportDocument then
set extension hidden of (file exportDocument as alias) to false
-- reveal (file exportDocument as alias)
end if
end tell
return
on error_handler(nbr, msg)
return display alert "[ " & nbr & " ] " & msg as critical giving up after 10
end error_handler