Converting Powerpoint to PDF inside DT3

If I do the following:

  • right click on a word document and select convert to PDF I get a PDF version a few seconds later inside the same folder

However if I do the same for a PowerPoint file I get nothing (and as far as I can see no message telling me it failed or is not possible).

I wouldn’t expect this conversion with proprietary formats like this. (I’m amazed the Word doc converted in the first place.) Perhaps @cgrunenberg has some magic up his sleeve to support other types, but I would normally assume the export would have to be done in the native application.

Word documents are supported by macOS’ text engine and can therefore be converted, other proprietary file formats like PowerPoint can be only previewed via Quick Look but not processed in any way.

1 Like

It would be helpful if the user had some feedback on this during the operation. For example the option to convert to PDF should not exist or be grayed out for non-supported file formats or a visual indication that it did not work.

1 Like

Failed conversions are logged to Windows > Log (whether this panel is automatically shown depends on its settings)

I just found some AppleScript online that does this. It didn’t work initially, but I managed to get it to work.

Here is the code:

on PPToPDF(input)
	set theOutput to {}
	tell application "Microsoft PowerPoint" -- work on version 15.15 or newer
		launch
		repeat with i in input
			set t to i as string
			if t ends with ".ppt" or t ends with ".pptx" then
				set pdfPath to my makeNewPath(i)
				open i
				repeat while active presentation is missing value
					delay 0.1
				end repeat
				save active presentation as (save as PDF) in POSIX file pdfPath
				set the end of theOutput to pdfPath
			end if
		end repeat
	end tell
	tell application "Microsoft PowerPoint" -- work on version 15.15 or newer
		quit
	end tell
	return theOutput
end PPToPDF

on makeNewPath(f)
	set t to f as string
	if t ends with ".pptx" then
		return (text 1 thru -5 of t) & "pdf"
	else
		return (text 1 thru -4 of t) & "pdf"
	end if
end makeNewPath

tell application "DEVONthink 3"
	set theSelection to the selection
	if theSelection is {} then error "Please select a record"
	set filepath to the path of the first item of theSelection
	set filePaths to {}
	repeat with fileItem in theSelection
		set end of filePaths to the path of fileItem
	end repeat
	set theOutput to my PPToPDF(filePaths)
	return theOutput
end tell

Thank you for sharing, @Sushi. This would be great for batch converting PPT documents.

Unfortunately, on my end, at first it seems to work (PPT opens) but then no new PDF is created in DevonThink. Probably user error, but let me know if there’s anything I could try to fix it.

Afaict, the script does not create a record but returns the path of the created PDF. No idea to what it returns this path. I’d try to import this file in the script.

can you give me a screen recording of how it looks like? It works on my end :slight_smile:

It was because the template that I used actually returned the path. I did not change that part hmmm

I was talking about these two lines:

The first one sets the variable theOutput to the return value of PPTtoPDF (which seems to be a list, BTW). The second line then returns this list. My question was: Where does it return this list to?

I’ll try to summarize in my words what the code might (! - given the lack of comments, I can only guess) be attempting to do.

  • get the currently selected records from DT
  • build a list of all the paths of these records
    • as an aside: This could be simply done by set filePath to path of selected records or something similar (I’m not an AppleScript person, so just guessing)
  • path this list of paths to PPTtoPDF
  • Inside PPTtoPDF loop over all paths and
    • open the the file in PowerPoint
    • create a new path by replacing pptx? with pdf (see below)
    • save the presentation as PDF to the new path
    • append the PDF name to theOutput

The “create a new path” gives me the creeps. If we’re talking about presentations that are imported (!) into DT (as opposed to index – again, the lack of comments does not help), the paths you’re working with are pointing to files inside DT’s database(s). Which is not a problem (yet).

However, you’re creating a new file (the PDF) inside DT’s database(s) (same path, different extension). That is a bad idea (provided that we’re talking about imported files!). DT maintains its database files and their metadata in structures that are different from the files. Now if you add a file to the guts of DT’s database(s), you’re circumventing DT’s housekeeping and metadata storage. That’s a very bad idea.

You should rather save the PDF to a location outside of DT (like a folder on your desktop) and import it into DT from there.

Some unrelated remarks on the code:

end tell...tell application "Microsoft PowerPoint"

is quite pointless. All the preceding code referred to MS PowerPoint, so simply leave out the end tell ... tell lines here.

  • what is all that theOutput stuff about? The list is not used, but still appended to?
  • ìf t ends with ...: I would not check for pptx? in the handler but rather weed them out in the calling part. Check out the whose method for this. It is blindingly fas. It is a lot neater to pass only the relevant data to the handler than having it check.
  • Why do you set filepath to ...if you never even use filepath later?
  • What is set to to f as string supposed to do? You’re passing a path into this handler, that must be a string anyway. You’re already assuming it is in if t ends with ".ppt" anyway in PPToPDF. I’d change that to
on makeNewPath(f)
	if f ends with ".pptx" then
		return (text 1 thru -5 of f) & "pdf"
	else
		return (text 1 thru -4 of f) & "pdf"
	end if
end makeNewPath
  • and, ceterum censeo, I’d write the whole thing in JavaScript :wink: