Jump to content
vdesabou

Convert word document to PDF [Version 1.6]

Recommended Posts

Hi - I'd like some help with this, the updated workflow doesnt download, I just get a message saying "not found" 

 

I would love to have a workflow to convert word docs to PDF easily!

 

Thanks!

Share this post


Link to post

Hi - I'd like some help with this, the updated workflow doesnt download, I just get a message saying "not found" 

 

I would love to have a workflow to convert word docs to PDF easily!

 

Thanks!

 

Please try again, I fixed the download link

Share this post


Link to post

Is there no Yosemite support? Doesn't work for me on 10.10.1

 

Yeah, it's broken. Looks like Microsoft screw up something with "Save As" support..

 

This simple applescript is giving error "Microsoft Word got an error: active document doesn’t understand the “save as” message. (-1708)":

tell application "Microsoft Word"
	open "Macintosh HD:Users:vdesabou:Downloads:test.doc"
	save as active document file format format PDF file name "Macintosh HD:Users:vdesabou:Downloads:test.pdf"
end tell

This must be working normally..So it looks a Microsoft Word issue to me. So it's unlikely to have a fix for this workflow soon.

 

EDIT:  Word 2011 version 14.2.0: It is working properly. With Word 14.4.7 it is broken.

 

In any case, the source code is open source and available here https://github.com/vdesabou/alfred-convert-word-to-pdf so if you want to have look, you can. If you find anything, you can do a Pull Request.

Edited by vdesabou

Share this post


Link to post

[EDIT] Having read the thread from the start it turns out that this is actually Vincent's workflow thread.  I'll say then that this workflow is working for me on Yosemite 10.10.1 with Office 2011 using the method I describe below.

 

I'm using Yosemite 10.10.1 with a KShell script called converttopdf.ksh by vdesabou (Vincent) that I'm pretty sure I hear about on these forums.  It creates a PDF version of a highlighted word document in Finder in the same folder as the original .doc file.  The Shell script runs a separate applescript called converttopdf.applescript for the conversion then it brings up options so that I can automatically send the newly created PDF as an email.  

 

I have a keyboard command of OPTION-CMD-P that will trigger this workflow.  I use it many times a day.

 

Vincent's Github link for his KShell script is here

 

I'm no shell expert but I'm sure someone here can adapt Vincent's script to just convert to PDF. 

 

My workflow is to use Alfred's "run script" workflow option with a keyboard combination to trigger 

ksh converttopdf.ksh "{query}"

in Alfred with the appropriate converttopdf.ksh and converttopdf.applescript scripts held is a workflow folder 

 

The converttopdf.applescript script as I have it (from 2013) is copy & pasted below.  It could be that this is that same applescript you guys are trying to run directly from Alfred, I'm not sure if it was written by Vincent

on run theQuery
set these_files to {}
-- Convert to PDF
set keep_duplicates to "Keep Duplicates"
set keep_original to "Keep Original"
set microsoftWordWasRunning to "false"
 
set text item delimiters to " "
set these_files to text items of (theQuery as string)
set the_counter to count of these_files
set text item delimiters to ""
repeat with i from 1 to the_counter
set cur_file to (POSIX file ((item i of these_files) as string)) as string
set file_name to (remove_extension(cur_file) & ".pdf")
file_name
tell application "Microsoft Word"
open cur_file
tell application "Finder"
if exists file file_name then
if keep_duplicates is "Discard Duplicates" then
delete file file_name
else if keep_duplicates is "Keep Duplicates" then
set file_name to (file_name & "(duplicate).pdf")
end if
end if
end tell
save as active document file format format PDF file name file_name
close document 1 saving no
if keep_original is "Discard Original" then
tell application "Finder"
delete cur_file
end tell
end if
end tell
end repeat
end run
on remove_extension(file_name)
set theCharacters to characters of file_name
set theReverse to reverse of theCharacters as string
set extension_length to (offset of "." in theReverse) + 1
set cut_file to (text 1 thru -extension_length) of file_name
end remove_extension

The converttopdf.ksh script as I have it (from 2013) is copy & pasted below, I've been using the script combination since April 2013 so the version on Vincent's Github page may well be updated/different but as it's working perfectly for me I really haven't seen any point in changing what I'm currently using. 

#!/bin/ksh -p
#set -x
 
#Set IFS variable to only separate on tabs
IFS=$'\t'
 
#Create an array with the tab-delimited files passed from Alfred
filesFromAlfred=(`echo "$1"`)
 
#Loop through each file in the array
for file in ${filesFromAlfred[@]}
do
IFS=$'\n'
    #do something with the file
filename=$(basename "$file")
filedirname=$(dirname "$file")
extension="${filename##*.}"
filename="${filename%.*}"
 
 
cp $file /tmp/tmp.$extension
 
osascript converttopdf.applescript "/tmp/tmp.${extension}"
if [ $? != 0 ]
then
if [ -f /tmp/tmp.${extension} ]
then
rm /tmp/tmp.${extension}
fi
echo "ERROR during conversion of $file"
continue
fi
 
if [ -f /tmp/tmp.pdf ]
then
mv /tmp/tmp.pdf ${filedirname}/${filename}.pdf
echo "${filedirname}/${filename}.pdf"
fi
 
if [ -f /tmp/tmp.${extension} ]
then
rm /tmp/tmp.${extension}
fi
done
 
#Reset IFS to its original state
unset IFS
 
osascript <<EOT
tell application "Alfred 2" to search "${filedirname}/${filename}.pdf"
EOT
 
exit 0
Edited by MacOCD

Share this post


Link to post

 

[EDIT] Having read the thread from the start it turns out that this is actually Vincent's workflow thread.  I'll say then that this workflow is working for me on Yosemite 10.10.1 with Office 2011 using the method I describe below.

 

 

Yes that's the same thing  :)

 

Which version of Microsoft word 2011 do you have installed?

 

I have a Mac which has version 14.2.0 and the workflow works.

My another Mac has version 14.4.7 and the workflow is broken.

 

So the problem is not related to Yosemite, it is related to an update Microsoft made which has broken the Apple Script "Save As" support, and I can't find anywhere someone complaining about it. I'm not sure how to report bugs to Microsoft, I'll have a look...

Share this post


Link to post

Yes that's the same thing  :)

 

Which version of Microsoft word 2011 do you have installed?

 

I have a Mac which has version 14.2.0 and the workflow works.

My another Mac has version 14.4.7 and the workflow is broken.

 

So the problem is not related to Yosemite, it is related to an update Microsoft made which has broken the Apple Script "Save As" support, and I can't find anywhere someone complaining about it. I'm not sure how to report bugs to Microsoft, I'll have a look...

 

I have 14.4.6 Installed and working on 2 different Macs.   I will definitely not update them until we know there is a work around :)

 

Thank you so much for your original script, it's been really useful to me.

Share this post


Link to post

Not sure if this workflow is being maintained anymore, but it was working great for me until I started using Word 2015 on the Mac. Since then it has stopped working. Any ideas on how to modify either script file to get it working again? Thanks!

Share this post


Link to post

Not sure if this workflow is being maintained anymore, but it was working great for me until I started using Word 2015 on the Mac. Since then it has stopped working. Any ideas on how to modify either script file to get it working again? Thanks!

Microsoft broke AppleScript with their update starting from 14.4.7 and did not fix it yet.

I don't have Word 2015 and I don't plan to purchase it, so I can't help..

 

But the source code is on Github, so anyone can fork and fix it for Word 2015

Share this post


Link to post

Not sure if this workflow is being maintained anymore, but it was working great for me until I started using Word 2015 on the Mac. Since then it has stopped working. Any ideas on how to modify either script file to get it working again? Thanks!

 

I have created a new workflow compatible with Word 2016.

Edited by xilopaint

Share this post


Link to post

In case anyone is still using version 1.2 of this (like I was) it will work in Mojave with Word 2016 if you change the lines in the Applescript

 

save as active document file format format document default file name thePDF

 

to 

 

save as active document file format format PDF file name thePDF

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...