Printing Outlook message as pdf

I’m running ML 10.8.5 and Outlook 2011 Mac.
As part of my workflow, I’d like to be able to save any email message I drag onto a droplet as a pdf in a folder (FMTemp) on the desktop.
Outlook scripting allows for printing “as pdf”. So thats exactly what i would like to do.
But the script I created definitely refuses to work. can someone please tell me what I’m doing wrong i following script:

tell application “Microsoft Outlook”
set myMessage to item 1 of (get current messages)
print myMessage with properties {as pdf:true, path name:“MAC HD:Users:BDJ:Desktop:FMTemp:test.pdf”}
end tell

Thanks in advance.

The Print command (Applescript Outlook Dictionary) seems to have a strange behaviour.
The script below does not generate a pdf, but instead prints the message on the default printer. This is not as specified in the properties. It seems as if the properties are completely ignored.
Anyone an idea what can be the cause?

set DestPath to “file://MAC HD/Users/BDJ/Desktop/FMTemp/test.pdf”
tell application “Microsoft Outlook”
set myMessage to item 1 of (get current messages)
tell myMessage
print myMessage with properties {as pdf:true, path name:DestPath}
end tell
end tell

One thing I learned is that the path name must be the complete url of destination pdf file, including file name.

I’ve done some additional testing and it turns out that the following command

print myMessage with properties {as pdf:true, path name:"file:/Macintosh/Users/BDJ/Desktop/Test/test.pdf"}

works wrongly. Instead of producing a pdf of the message, it simply prints the message on the default printer.

Can someone please crosscheck and eventually figure out what this is all about?
I don’t undertand.

Thanks.

Hi,

I don’t have Outlook but the path string format looks wrong.

path strings starting with file: are string representations of file URLs, the correct format is file:///Mac HD. with 3 slashes, two for the URL scheme and one for the root volume.

I doubt that a file URL will work, try a colon separated HFS path:


set DestPath to (path to desktop as test) & "FMTemp:test.pdf"
.

Hello Stefan,

This doesn’t solve the problem. In the Applescript Dictionary coming with Outlook, it is clearly stated that is has to be a URL to the destination file. So thanks for your input with the three slashes.

However, the command continues to send the file to our default printer instead of turning it in a pdf.

Does someone have any idea?

Thanks.
Bernard.

Next try: put the keyword file in front of the path

set DestPath to file ((path to desktop as test) & "FMTemp:test.pdf")

Hello.

A last thing that may work, (and you may google and configure it by yourself!) is to use the Url for a cups queue that is configured for creating pdf’s from its input, caveat is, that you’ll have to rename it afterwards.

I’m just writing this for the case that every other thing fails.

Hello to everyone,

First of all thank you to all of you who tried to help.
Yesterday I became an email from MPetz, which I would like to copy here because it is the answer to the question:

In short: the URL you have to use (yes Stefan it is definitely a URL)
is not “file:///MAC HD/Users/XX_Your_User_XX/Desktop/XX_Your_Folder_XX/test.pdf”
but is “file:///Users/XX_Your_User_XX/Desktop/XX_Your_Folder_XX/test.pdf”

Here is PMetz’s Post:

START OF POST
I’ve been trying to do the print to PDF in outlook as well but also couldn’t figure out what was going wrong for me…the path or the way I was writing the command to print or what. Well I did another google search for it this morning to see if I could find any info and found your post that showed you were trying to do the same thing I was.

So I dug a little into figuring out what this ‘file URL’ really was. I did a quick search and came up with the idea to take the folder I wanted to save to (a folder called working on my desktop) and drag it into safari to get the URL. The folder thing didn’t work so I used a file IN the folder ‘working’ and that worked. I used that url (minus the filename) and added test.pdf

Used your script and it worked.

set DestPath to “file:///Users/XXuser_name_herexXX/Desktop/Working/test.pdf”

tell application “Microsoft Outlook”

set myMessage to item 1 of (get current messages)

tell myMessage

	print myMessage with properties {as pdf:true, path name:DestPath}

end tell

end tell

END OF POST

Thanks again to PMetz.

Best Regards.
Bernard.

Hi,

I copied and pasted your script but it is not working “ the only thing that I changed is the name of my user folder. The following message box appears in Outlook:

Print
Error while printing.

The script terminates with the result “error “User canceled.” number -128”

I would greatly appreciate your suggestions!


tell application "Microsoft Outlook"
	
	set DestPath to "file:///Users/XXXXXX/Desktop/Working/test.pdf"

	tell application "Microsoft Outlook"
		
		set myMessage to item 1 of (get current messages)
		
		tell myMessage
			print myMessage with properties {as pdf:true, path name:DestPath}

		end tell
	end tell
end tell

Model: OSX v 10.9.5 & Outlook v15.3
AppleScript: 2.6.1
Browser: Firefox 33.1
Operating System: Other

If you are trying to use the script as is, I would suggest making sure you had a folder on your desktop called working.

Old thread, no working solution tho

Dictionary : path name (text) : Complete url of destination pdf file, including file name. if directory url preceeding file name is not valid, does not create an output file.


-- These 2 work
--  // (they are 2) before test.pdf ? why
set DestPath to "file:///Users/one/Desktop//test.pdf"
--or
set DestPath to POSIX path of (path to desktop) & "test.pdf"


But works

I will repeat once again. The destination file should exist already (be valid) to write to it. You should firstly create empty file using Finder or System Events. Other solution may work this time, but the dictionary say you: do this, other solutions may not work in the future:


tell application "Finder"
	try
		set DestPath to URL of (make new file at desktop with properties {name:"test.pdf"})
	on error -- file exists already
		set DestPath to URL of file (((path to desktop) as text) & "test.pdf")
	end try
end tell

tell application "Microsoft Outlook"
	set myMessage to item 1 of (get current messages)
	print myMessage with properties {as pdf:true, path name:DestPath}
end tell

Hi KniazidisR

I have tried the paths, it does create the file on desktop, tried download folder too.

But cant test the script until I get over this error “item of {}”,

frustrating → all I want is a well formatted pdf of email which apple mail can’t, unless u have suggestion for converting .eml to pdf

Cheers