Microsoft PowerPoint 2016 for Mac (aka version 15) has a strange quirk - when I copy and paste images from Preview or most other applications, the image gets copied in Tagged Image File Format (TIFF). The image is practically uncompressed (or possibly minimally compressed), resulting in very, very huge PPTX files! Plus: Removing unwanted font references.

For me, PowerPoint only "pastes" images as TIFF. You can test it as follows:

  1. Open an image in Preview
  2. Then Copy it to clipboard
  3. In PowerPoint, from the File menu, select Paste Special..., where you only have the option of TIFF:

PowerPoint for Mac Paste Special, only supports TIFF images

  1. Now, copy the image you just pasted, and repeat Paste Special... - you'll have options to paste as TIFF, PDF or Microsoft Office Graphic Object.

PowerPoint for Mac Paste Special, repeated with TIFF, PDF and Microsoft's internal format

Here's the strange part, do the same in Microsoft Word, step 4 above will give you the option to paste as PNG or JPEG in addition to the other formats! Here it is in Word:

Word for Mac Paste Special, converts images to TIFF, PNG and JPG

No TIFFs please!

The option to copy the image from the clipboard either as PNG or JPEG (JPG) is great because I can choose, either:

  • Lossless compression with PNG - which offers crisp screen shots of UI elements like dialog boxes or screen shots of text from a browser window,
  • Lossy compression with JPEG - which is best of pictures, or screen shots of pictures in a browser window, because the files are smaller with little noticeable degradation in quality.

I have received PPTX's from other PowerPoint for Mac users, and I notice they experience the same thing, i.e. huge file sizes for relatively few slides / images.

One could either select each image, then right-click > Save as Picture... in PNG format and then possibly right-click > Change Picture.... Or copy the image, paste it in Word, copy it again, and then paste special in PowerPoint. You'll then have to re-position, re-group, re-animate, or re-adjust - so this is absolutely nuts.

Fixing TIFFs automatically

Honestly, the first thing that occurred to me was to hack the PPTX file directly! Maybe a macro would've done the trick instead...

Anyway, for those who didn't know, the PowerPoint file with .PPTX extension is simply a ZIP file, so I decided to automate the process of:

  1. Extracting the contents of a PPTX (using unzip)
  2. Converting TIFFs to PNGs (using sips)
  3. Fix the references to TIFFs by pointing them to PNGs (using sed)
  4. Re-compress all the files (using zip)

That translates to the script below. Run it from Terminal with the first parameter being the PPT file name, e.g. ./fix.sh "my slides.pptx". Hopefully my readers know how to create and run shell scripts by now (remember chmod +x fix.sh)!

#!/bin/bash
unzip "$1" -d xtractd
cd xtractd/ppt/media
for x in *.tiff; do sips -s format png $x --out ${x/.tiff/.png}; done
rm *.tiff
cd ..
sed -i '' -e 's/\(Target="[^"]*\)tiff"/\1png"/g' slides/_rels/*.rels
cd ..
zip -r "../${1/.pptx/.[FIX].pptx}" *

sed is a tool to transform text. In sed, s/ indicates a substitution of the given regular expression (Target="[^"]*tiff") with a replacement string (\1png") for all matches /g. Also, \1 will copy the contents of first matching content of the regular expression in brackets \( and \). In my last post, Text Manipulation Cheat Sheet, I explained regular expressions.

That is, replacing:

<Relationship Id="rId2" 
 Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" 
 Target="../media/image1.tiff"/>

with:

<Relationship Id="rId2" 
 Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
 Target="../media/image1.png"/>

Fixing Fonts Automatically

I hate slides that use a ton of fonts that don't exist on my mac. Windows users have less of a problem since PowerPoint on Windows can embedded fonts into the PPTX. This is not available for macOS.

One could go to Format > Replace Fonts..., but that often fails to fully replace all fonts.

PowerPoint (trying and failing to) Replace Fonts

So, I figured I'd expand my script to fix the fonts too.

Here's the final script which takes one input (the PPTX file), and when it's done, launches PowerPoint for you to check the slides:

#!/bin/bash
if [[ -z $1 ]]; then echo $0 input_pptx [output_pptx]; exit; fi
if [[ ! -f $1 ]]; then echo File $1 not found; exit; fi
if [[ -z $2 ]]; then out=${1/.pptx/.[FIX].pptx}; else out=$2; fi
[[ -d xtractd ]] && rm -i -r xtractd
[[ -f $out ]] && rm -i "$out"
unzip "$1" -d xtractd
cd xtractd/ppt/media
for x in *.tiff; do sips -s format png $x --out ${x/.tiff/.png}; done
rm *.tiff
#/Applications/ImageOptim.app/Contents/MacOS/ImageOptim *.png *.jpg *.jpeg
cd ..
sed -i '' -e 's/\(Target="[^"]*\)tiff"/\1png"/g' slides/_rels/*.rels
sed -i '' -e 's/\(typeface="\)[^"]*"/\1Calibri"/g' slides/*.xml notesSlides/*.xml slideLayouts/*.xml slideMasters/*.xml
cd ..
zip -r "../$out" *
cd ..
rm -r xtractd
open "$out"

I've hard coded stuff like the folder for temporary unzipped files xtractd, the output file name [FIX], and the replacement font Calibri. There is practically no validation or error handling either, be warned!

Also:

  • You can attempt to further decrease the PPTX file size by compressing images using ImageOptim. I've posted about using ImageOptim when capturing screenshots.
  • And, you could also remove unwanted font references in other XML files, e.g. theme and notesMasters.
  • It would be nice if I bothered to leave specific fonts intact e.g. based on the design, or standardize on header/body fonts, but I leave that to you.

Conclusion

So, this is my quick and dirty hack to "fix" a couple of deficiencies with PowerPoint files on mac - changing TIFF images to PNGs and removing the multitude of, often Windows-specific, fonts.