Search code examples
vbapdflatexpowerpointtexmaker

Power-point 2013 export to latex with pdfcrop


I have a powerpoint presentation with ~ 100 slides.

Each slide has a figure. I edit each slide [work on each figure] and then save each slide separately as in pdf format.

I crop every pdf separately in adobe acrobat to remove whitespace and some other slide elements I don't want to go in final figure. Then I include this pdf in Texmaker as a figure, for my latex document. This process is highly inefficient.

Please suggest some ways I can automate this process partially or completely.

I tried recording macro in powerpoint to automate at least saving the current slide as pdf part, but it opens a vba window on clicking define macro through developer's tab and I have no knowledge of vba scripting.

Thanks.


Solution

  • Is there a reason for exporting as PDF instead of a raster format such as JPG or PNG? There are some open source solutions that could be called from VBA to crop those image formats. If you need PDF, then this macro will do what you need:

    Option Explicit
    
    ' *********************************************************
    ' Purpose : PowerPoint VBA macro to export slides as either
    '           and image or a PDF.
    ' Author  : Jamie Garroch from htpp://youpresent.co.uk/
    ' Date    : 17MAY2016
    ' *********************************************************
    Sub ExportEachSlidesAsPDF()
      Const myPath = "C:\Temp\"
      Dim oSld As Slide
      For Each oSld In ActivePresentation.Slides
        ' The next commented line exports the slide as a JPG
        'oSld.Export myPath & ActivePresentation.Name & " Slide " & oSld.SlideIndex & ".jpg", "JPG"
    
        ' Export each slide as a PDF
        With ActivePresentation
          .PrintOptions.Ranges.ClearAll
          .PrintOptions.Ranges.Add oSld.SlideIndex, oSld.SlideIndex
          .ExportAsFixedFormat2 Path:=myPath & ActivePresentation.Name & " Slide " & oSld.SlideIndex & ".pdf", _
            FixedFormatType:=ppFixedFormatTypePDF, _
            Intent:=ppFixedFormatIntentPrint, _
            FrameSlides:=msoFalse, _
            HandoutOrder:=ppPrintHandoutHorizontalFirst, _
            OutputType:=ppPrintOutputSlides, _
            PrintHiddenSlides:=msoFalse, _
            PrintRange:=.PrintOptions.Ranges(1), _
            RangeType:=ppPrintSlideRange
        End With
      Next
    End Sub