Saturday, November 24, 2007

Creating a PDF from Powerpoint WITH Custom Animations

Updated: New and improved code can be found at PowerPoint -> PDF (Part 2).

I like to write talks in PowerPoint, because it has a nice interface and is a lot faster to work with for diagrams than Latex. I hope one day to move to using Google's online presentation creation tool, but there is one crucial feature missing that stops me - creating PDF's. If I am going to a place away from York, to present on another persons machine, the format I can guarantee that will display correctly is PDF.

Until now I've never written PowerPoint slides with "custom animations". A custom animation is something as simple as a slide where additional elements become visible with each click, like a pop-out box appearing or a circle around some relevant part of the slide. While its usually sufficient to get away without this feature, it is sometimes very handy. The reason I've stayed away is because of the conversion to PDF.

When Latex creates a slide with many sub-elements which appear at different stages, it creates multiple pages in the PDF. However, when using either OpenOffice's PDF converter or the Acrobat converter all the sub-elements are placed on one slide and are visible at all times - loosing the entire point of hiding elements!

I looked around the web for a tool to solve this problem, without success. I found one tool that seemed like it might help, but appeared to rely on having Acrobat Creator installed locally. I write my presentations on my machine, then remote desktop to the University machines to do the PDF conversion, and on those machines I don't have admin access. In addition, this tool required money to use, and may still not have worked.

Instead I wrote some VBA code, which deconstructs the slides with animations into multiple slides, then puts them back together after. The two macro's are called AddElements and RemElements. The code to AddElements cycles through each slide, duplicating it once for each level of clicky-ness in the animation, deleting the elements that shouldn't be visible yet, and hiding the original.

To run the code go to Tools/Macro/Visual Basic Editor, copy and paste the code into a project, then go to Tools/Macro/Run Macro and run AddElements. You can then use Acrobat to create a standard PDF, and after you are finished, run RemElements to put the project back to the way it was. Like all code you find on the net, please backup your presentation before you start - no warranties are offered or implied!

The code is:


Sub AddElements()
Dim shp As Shape

Dim i As Integer, n As Integer
n = ActivePresentation.Slides.Count
For i = 1 To n
Dim s As Slide
Set s = ActivePresentation.Slides(i)
s.SlideShowTransition.Hidden = msoTrue

Dim max As Integer: max = 0
For Each shp In s.Shapes
If shp.AnimationSettings.Animate = msoTrue Then
If shp.AnimationSettings.AnimationOrder > max Then
max = shp.AnimationSettings.AnimationOrder
End If
End If
Next

Dim k As Integer, s2 As Slide
For k = 0 To max
Set s2 = s.Duplicate(1)
s2.SlideShowTransition.Hidden = msoFalse
s2.MoveTo ActivePresentation.Slides.Count

Dim i2 As Integer
For i2 = s2.Shapes.Count To 1 Step -1
With s2.Shapes(i2)
If .AnimationSettings.Animate = msoTrue Then
If .AnimationSettings.AnimationOrder > k Then
.Delete
Else
.AnimationSettings.Animate = msoFalse
End If
End If
End With
Next
Next
Next
End Sub

Sub RemElements()
Dim i As Integer, n As Integer
Dim s As Slide
n = ActivePresentation.Slides.Count
For i = n To 1 Step -1
Set s = ActivePresentation.Slides(i)
If s.SlideShowTransition.Hidden = msoTrue Then
s.SlideShowTransition.Hidden = msoFalse
Else
s.Delete
End If
Next
End Sub


Enjoy!

39 comments:

Anonymous said...

Nice hack, Neil!

Anonymous said...

Just awesome... you made my day :) Thank you so so much

Anonymous said...

Hi, I'd really like to use your code but ca't figure out where exactly to paste it. Please could you explain it.

Thanks

Neil Mitchell said...

Anon: Tools, Macros, Visual Basic Editor.

Erica said...

Hi, Your code was a big help converting my powerpoint animations so that it could be viewed on slideshare. Thanks! My only suggestion for improvement is to recognize when multiple animations are supposed to happen at the same time (e.g. one element appears while another disappears). Anyways, I was able to work around this constraint, and your code saved me a lot of time. Thanks again.

btw, I cited this post on
my slideshare (in the description section).

Best, --Erica

Erica said...

Shoot! I'm dumb and just now saw you had a new and updated version up. Anyways, I'll bookmark it and try it next time. Thanks again!

Neil Mitchell said...

Erica: Glad you liked it. I still have the intention to package this up and put it on my home page - given it's use for others I'll definitely try and do that soon.

I also very much like the idea of slideshare.net, I think I'll have to try and start using that too.

Anonymous said...

Thanks a ton! That was invaluable -and easy enough to follow even for me!

PowerPoint said...

Geeez! Some great audience you have! Lol. Well,it's always best to come up with activities you and your audience can interact. Thanks for sharing and more power

Jônadas said...

Very nice code! Is there any easy way to export it for use with OpenOficce (LibreOffice) Impress? It has a similar tool called "libreoffice basic", but when I try to use your code as per instructions it says something like syntax error". Any suggestion would be really appreciated.

Neil Mitchell said...

Jondas: sorry, I don't have any experience with oo basic, if you make a tweak that does work please post it as a comment here so others can use it.

John D said...

This is great! I just added it to PowerPoint 2011 on Mac and it works like a charm. Thanks Neil!

I actually needed to do this in multiple presentations, so rather than copying and pasting it into each deck, I just created a separate "PDF generator.pptm" with these macros. Then I open the deck I want to turn into a PDF, and run the macros from the .pptm. Works perfectly.

mscanley said...

Neil:
Could you give me the steps on how to do this using PPT 2010? I can't seem to be able to paste into Visual Basic Editor so I'm at a loss. Thanks.

Neil Mitchell said...

mscanley: Can you download this file? http://community.haskell.org/~ndm/darcs/office/PowerFlat.bas Then if you import that into powerpoint you should be able to run the macro even if you can't edit it.

Ryan D said...

Neil,

Thanks for this script. You saved me many hours doing this manually.

Great job,

Thanks,
Ryan D

Anonymous said...

Hello,

Thanks for this tip that is really useful.

Just a drawback: the incrementation of the slides numbers :-( (my final slide is slide # 99/15)

Do you have a trick to avoid this?

Thanks in advance ;-)

Anonymous said...

Hello,

Thanks for this tip that is really useful.

Just a drawback: the incrementation of the slides numbers :-( (my final slide is slide # 99/15)

Do you have a trick to avoid this?

Thanks in advance ;-)

toto said...

Hello,

Thanks for this tip that is really useful.

Just a drawback: the incrementation of the slides numbers :-( (my final slide is slide # 99/15)

Do you have a trick to avoid this?

Thanks in advance ;-)

Anonymous said...

Thanks for this scripts. It helped a lot.

Nishith said...

Thanks a lot for this. It helped a lot.

Anonymous said...

thanks a lot!!!!!!!!!!!!!!!!!

Anonymous said...

Pretty good man thanks!

Anonymous said...

What can I say? You saved me! I have a huge ppt...with lots of pictures and dynamics inside...Now I have a nice pdf!

Thank you so much!

dash said...

Excellent, thanks a lot !!!

Thanikachalamurthi said...

OMG, I did not backup and I tried the macro addition and now I lost the content ..Awwww.. :-(

Susan said...

Hi, thanks a lot, but in my 'SAVE AS' box there is no PDF in the target format. Please what else can I save it as, or how else can I go about it? I am using powerpoint 2007. Thank you so much as I await your reply.

Neil Mitchell said...

Susan: I'm on 2010, and there is a save as PDF option. Afraid I've never used 2007 so no idea what it might be.

Anonymous said...

This is some nice piece of work. Made my day much easier. Thank you.

bMac said...

Hey Neil,

Great work on this. Really appreciate you taking the time to do it.

Unfortunately it is not working for me. After pasting the code and running AddElements I get a Run-time error: AnimationSettings (unkown member): invalid request.

The debug shows it takes an issue with this line: If shp.AnimationSettings.AnimationOrder > max Then

Any thoughts on what this might be?

Some things of note:

I'm on MacOS Sierra 10.12.6
Using PPT for Mac 15.41
I did not create this PPT file and know very little about PPT.

Neil Mitchell said...

Mac is quite different and this code is quite old. Afraid I’ve no idea.

bMac said...

Yeah I figured as much. Thanks!

Unknown said...

Does this tool work to preserve GIF animations within the Powerpoint? If not, are you aware of any tool that can preserve GIFs in PDFs?

Anonymous said...

Amazing. Thank you very much for this great help. Great Job.

GapSpace said...

Great tool, thanks a lot!

Gaurav Jaiswal said...

sir, please help me to understand the procedure to create pdf with custom animation of ppt. i tried with trigger animation but it didn't work. please help me sir

Unknown said...

Thank you..this is great but it not applying to my disappearing animation. Please help.
Thank you.

Neil Mitchell said...

Unknown: Afraid I haven't looked at this code in a very long time - if it works for you, great, but if not, then I'm afraid you are on your own.

Anonymous said...

For LibreOffice/OpenOffice users, this macro code will not work. However, the following extension seems to accomplish the same thing!

https://github.com/monperrus/ExpandAnimations

Anonymous said...

This helped me so much, thank you!