MS PowerPoint "Print to File" Not Working

Hello,
I’d like to automate printing PPT slides to PDFs.
I adapted the code from elsewhere but the code is not working.
The problems:

  1. Although I set the print out parameter to print to file, but it will still send to the default printer (with parameter without showDialog).
  2. The print options does not seem to work either (with parameter with showDialog, the Dialog sheet does not reflect the print options properties.).

Here is the code:

set filepath to ((path to desktop) as Unicode text) & "myfile.pdf"
tell application "Microsoft PowerPoint"
	set myPres to the active presentation
	set myPrintOpts to the print options of myPres
	tell myPrintOpts
		set print color type to print color
		set output type to print four slide handouts
		set print hidden slides to false
		set range type to print range all
	end tell
	print out myPres ¬
		print to file filepath ¬
		without showDialog
end tell

the AppleScript Dictionary of MS PowerPoint shows that the print to file parameter type is text. It doesn’t say it should be the path of the output PDF file. So maybe I’m misunderstanding the command?

image

Any help appreciated!

For PDF, you need to use something like:

save presentation docName in pdfFilePath as save as PDF

If you have a particular reason to use print out - does it provide additional options compared to save? - then you’ll probably need a virtual PDF printer such as VipRiser or PDF Printer.

Hi @leo_r,

Thanks for your tips.

I’m not from programmer background and did not know the save command. When I export to PDF manually, I’ve always been using CMD+P.

I tried the save command. It does save the presentation to PDF, but I don’t see where I can adjust the print options. I want to have four slides on one page, etc.

It’s OK for me to print out the presentation with showDialog. The problem is: Although I have set the properties of the presentation to

set print color type to print color
		set output type to print four slide handouts
		set print hidden slides to false
		set range type to print range all

The dialog does not reflect these properties at all.

My main goal is to automate these print settings.

I tried the UI element, but AppleScript does not seem to recognize these options (the options in the box in the screenshot below).

image

I’m not aware of any way to create PDF using the print out command (if it exists, then I’m sure others will chime in).

Like I mentioned, you’ll need a virtual PDF printer. You’ll set it as your current printer and it will produce PDFs.

The ones I’m aware of are VipRiser and PDF Printer. The functionality of free versions has some limitations:

There’s also free PDFwriter but it’s not exactly user friendly:

Let me know if you need more info.

There’s also a commercial app BatchOutput PPT which automates printing and exporting from PowerPoint (you’ll still need a virtual PDF printer for your requirements). Full disclosure: I’m the developer.

Thanks, @leo_r, for all the information.

I had some tests with showDialog and it looks like the AppleScript commands provided by MS have bugs and limitations.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Microsoft PowerPoint"
	set myPres to the active presentation
	set myPrintOpts to the print options of myPres
	tell myPrintOpts
		set fit to page to false
		set print color type to print black and white
		set output type to print four slide handouts
		set print hidden slides to true
		set frame slides to true
	end tell
	print out myPres ¬
		with showDialog
end tell

the print four slide handouts property does not work, but if I change to print three slide handouts, it works. Changing the number to two also works. Only the number four does not work, although the option is in the library.

set print color type to print black and white will set the print option to print Grayscale (not black and white).
set print hidden slides to true does not work. The box is still unchecked.
set frame slides to true does not work. The box is still unchecked.
set fit to page to false does not work. The fit page box is still checked.

Further, the library does not seem to offer option to set the paper orientation.

With the above code, here is the popup dialog:

Continuing my previous post (I’m only allowed to post one media, so I have to post the other one in a separate post):

Now, if I change print four slide handouts to print three slide handouts. Here is the popup dialog:

So, it appears that the problem is not with Virtual Printer but with the AppleScript library provided by MS.

(disclaimer: I have no programming background, so my interpretation might be wrong.)

Yes, the AppleScript support of Office is a buggy mess, especially when it comes to output.

You won’t know how it works until you try, and the info provided in the Dictionary sometimes has nothing to do with reality.

I also have no idea how AppleScript commands would affect the actual controls in the Print dialog if you do showDialog.

May I suggest to try my BatchOutput PPT (no commercial solicitation, you can run it free for 30 days). I’m curious if it produces the expected results for you when you use a virtual PDF printer. There’s no magic - it uses the same AppleScript commands under the hood anyway:

https://zevrix.com/downloads/BatchOutputOffice.dmg

Thanks, I tried your app.
The result is the same. It’s not surprising since

it uses the same AppleScript commands

Setting:
image

(Result is shown in the next reply because I can only post one screenshot per post.)

1 Like

Result (it does not print 4 slides per page):

Ok I see.

Thanks for giving it a try.

Not surprised.

Like I mentioned, the AppleScript support of Office wasn’t that great to start with - and it only got worse through the years.

The AppleScript print support in Word was nearly completely destroyed with the release of Monterey.

I don’t know when the problems with PowerPoint started as users never reported this issue. I suspect that the demand for print automation from PowerPoint - which has never been that big - yet dwindled dramatically in recent years anyway.

Sorry that I don’t have any solution for you!

There’s also GUI scripting - that is, it might be possible to manipulate specific controls in the Print dialog via AppleScript (which isn’t related to PowerPoint dictionary). But I don’t have any experience with that and am not sure it would be reliable. Maybe others will chime in.

1 Like

P.S. In Word, some print functions that stopped working in AppleScript still do work in Visual Basic. However, Microsoft also helpfully removed the ability to send VB code directly from AppleScript several years ago.

So you might be able to achieve what you need by creating a VB Macro in PowerPoint (provided you know Visual Basic and are familiar with PowerPoint macro editor, of which I have only rudimentary knowledge).

If you do decide to go the route of installing a virtual printer, I’ve had great success with RWTS-PDFwriter. None of the others worked reliably. I’ve used it for years combined with AppleScript to print to PDF from VMware Fusion, Citrix Receiver (now Workspace), and VMware Horizon, since the native macOS PDF workflows are not available in virtual machines.

(Also note that macOS 14.0 Sonoma made significant changes to the printing system; printing to any local printers in VMware Fusion and VMware Horizon is currently broken for me.)

If you end up going that route, l can share some code that takes care of getting PDFwriter’s output.

1 Like

Hi @tree_frog,

I have installed RWTS-PDFWriter. I have not upgraded to macOS 14. If you could share some of your codes, it would be very helpful!
Thank you very much!