Jump to content

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!

 

Please try again, I fixed the download link

Link to comment
  • 5 months later...

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
Link to comment

[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
Link to comment

 

[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...

Link to comment

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.

Link to comment
  • 9 months later...

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

Link to comment
  • 2 months later...

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
Link to comment
  • 4 years later...

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

Link to comment
  • 1 year later...
3 hours ago, nesdroc said:

Is having word a precursor for using the workflow?

 

Yes. It uses Word to do the conversion.

 

3 hours ago, nesdroc said:

Just looking to be able to right click in finder and convert to pdf.

 

Have you looked at Automator, then? You can't run workflows from a context menu.

Link to comment
20 hours ago, deanishe said:

Have you looked at Automator, then?

 

It’s deprecated in favour of Shortcuts. End result is the same, since shortcuts can be used as Services.

 

21 hours ago, deanishe said:

You can't run workflows from a context menu.

 

We can add a Service which calls the Workflow via External Trigger.

Link to comment

@vitor and @deanishe Thanks for the input. I'll look at Shortcuts / automator and see what I can come up with. Seem to remember there being some "to pdf" in Shortcuts when I was using it on iPhone. Might just have tunnelen visioned a bit late as I'm discovery Alfred being new to it and all that my first thought now is to do everything using Alfred 😄

Link to comment

@vitor I found your Shortcuts workflow. With the argument option will I be able to pass a selected file in Finder? As to call it with the "Make pdf" Shortcut and have it receive whatever file (or files if possible) I have selected in Finder. 

 

Not sure if it's just a matter of ticking this box in your workflow? But have I feeling that would be too easy. 

223706809_Screenshot2022-01-19at07_10_00.thumb.png.d6d404a125fd7e4ec9eff9d9f467fa0b.png

Link to comment
On 1/19/2022 at 1:22 PM, vitor said:

The Workflow already has a File Action separate from that. That is specifically addressed in the very short instructions.

Ah, got it now. Don't have all the Alfred terminology down, so I was looking at the workflow and got confused with the unticked "Files" option. Got it going now. Thanks.

Link to comment

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...