OpenOffice PPT to SWF conversion

  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
  • : Function ereg() is deprecated in /home/bulahema/public_html/old/includes/file.inc on line 645.
The OpenOffice Basic macro is below.

The macro opens the ppt document and converts each slide to an .sxi file (OO's native presentation format). The reason for this step is that I've found OO does a better job of interpreting the vectors from an sxi file as opposed taking them from the ppt. The macro then converts each of the .sxi files to an individual .swf, and deletes the .sxi

The macro also collects slide titles, and writes them to an XML file in the destination directory (described below) along with the slide .swf's

The macro is expecting the following input variables

strFile - This the full path (path... not url) to the ppt document to be converted

dirName - this the full path to the destination directory for your slides and XML file. On windows, if the directory does not exist it will be created (don't know if that happens on Linux... let me know if it does).

If you're running this macro as an automated process, I stongly suggest you createa unique destination directory for each conversion.

Here's the code. I don't know if the forum will add any whitespace or newlines when I post the code, but this is basic so you'll need to check for whitespace at the end of each line when you build your basic file. If OO spits out errors you can't track down, let me know and I'll post the basic file for download.

The code also contains what's needed if you want a PDF from the slides as well. If you wan the pdf's, just look at the comments... you'll see which line to un-comment.

Code:

REM ***** BASIC *****

Sub Main(strFile, dirName)
     SplitSlides(strFile, dirName)
End Sub

Sub SplitSlides(cImpressDocToSplit, dirName)
     ' This is the name of the Impress document to split
     ' into separate documents.
     ' Each page of this Impress document is saved as a
     ' separate document, as a PDF, and also as a Flash.
     'cImpressDocToSplit = "enterPathManuallyForOverrideHere"
     
     
     ' Open the document to find out how many pages it has.
     oDoc = OpenDocument( cImpressDocToSplit )
     
     'Create the XML file for the document titles
      myNames = ""
     oDrawPages = oDoc.getDrawPages()
     'print aSlideNames
        ' Iterate over each page.
        For i = 0 To oDrawPages.getCount() - 1
      ' Get the page object
      oDrawPage = oDrawPages.getByIndex( i )
      ' Get the slide name
      cSlideName = oDrawPage.Name
      myNames = myNames+"<slide>"
      myNames = myNames+"<title>"
      myNames = myNames+cSlideName
      'Print cSlideName
      myNames = myNames+"</title>"
      myNames = myNames+"</slide>"
   Next
   myNames = myNames+""
   iNumber = Freefile
   aFile = dirName + cImpressDocToSplit+"_pre.xml"
   Open aFile For Output As #iNumber
   Print #iNumber, myNames
   Close #iNumber
     
     nNumPages = oDoc.getDrawPages().getCount()
     
     ' Now that we know how many pages it has, close it.
     oDoc.dispose()
     
     ' Get the name of the document, but without a filename suffix.
     cImpressDocToSplitNoSuffix = Left( cImpressDocToSplit, Len( cImpressDocToSplit ) - 4 )
     
     
     ' Now loop once for each page.
     nHighestPageNumber = nNumPages-1
'     nPageToSave = 2
     For nPageToSave = 0 To nHighestPageNumber
     
           ' Open the document.
           oDoc = OpenDocument( cImpressDocToSplit )
          
           ' Delete all pages except the one we're interested in keeping
           ' on this loop.
           DeleteAllPagesExcept( oDoc, nPageToSave )
          
           ' Prepare to save the document in multiple forms.
           ' First get the new filename to save it under.
           'cNewName = cImpressDocToSplitNoSuffix + " -- page " + CSTR( nPageToSave + 1 )
           'cNewName = dirName + cImpressDocToSplitNoSuffix + "_" + CSTR( nPageToSave + 1 )
           cNewName = dirName + "\slide_" + CSTR( nPageToSave + 1 )
           'print "Ouputting to " + cNewName

           ' Save the document as a new impress document.
           oDoc.storeToURL( ConvertToURL( cNewName + ".sxi" ), Array() )
           ' Save it as a PDF.
           'ExportToPDF( oDoc, cNewName )
           ' Save it as a Flash.
           ExportToSWF( oDoc, cNewName )
           ' Close the document without saving it.
           oDoc.dispose()
     Next
End Sub


' Pass in the pathname to an Impress document.
' This opens the document, and returns it.
Function OpenDocument( cImpressDoc )
     
     ' Open the Impress document.
     oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDoc ), "_blank", 0, Array() )

     ' Return the document
     OpenDocument() = oDoc
End Function


' Delete all pages of an Impress or Draw document,
' EXCEPT for a certian page that we want to keep.
Function DeleteAllPagesExcept( oDoc, nPageToKeep )
     nNumPages = oDoc.getDrawPages().getCount()
     nHighestPageNumber = nNumPages-1
     
     ' Delete the last page, then the page before that,
     ' then the page before that, until we get to the
     ' page to keep.
     ' This deletes all pages AFTER the page to keep.
     nPageToDelete = nHighestPageNumber
     Do while nPageToDelete > nPageToKeep
           ' Get the page.
           oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
           ' Tell the document to remove it.
           oDoc.getDrawPages().remove( oPage )
          
           nPageToDelete = nPageToDelete - 1
     Loop
     
     ' Delete all the pages before the page to keep.
     For i = 0 To nPageToKeep - 1
           ' Delete the first page.
           nPageToDelete = 0
           ' Get the page.
           oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
           ' Tell the document to remove it.
           oDoc.getDrawPages().remove( oPage )
     Next
End Function


Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
     Dim oPropertyValue As New com.sun.star.beans.PropertyValue
     If Not IsMissing( cName ) Then
           oPropertyValue.Name = cName
     EndIf
     If Not IsMissing( uValue ) Then
           oPropertyValue.Value = uValue
     EndIf
     MakePropertyValue() = oPropertyValue
End Function



Sub ExportToPDF( oDoc, cFilename )
     cUrl = ConvertToURL( cFilename + ".pdf" )
     
     oArgs = Array(_
                      MakePropertyValue( "URL", cURL ),_
                      MakePropertyValue( "FilterName", "impress_pdf_Export" ),_
                      )
     
     oController = oDoc.getCurrentController()
     oFrame = oController.getFrame()
     
     oDispatcher = createUnoService( "com.sun.star.frame.DispatchHelper" )
     oDispatcher.executeDispatch( oFrame, ".uno:ExportTo", "", 0, oArgs() )
End Sub



Sub ExportToSWF( oDoc, cFilename )
     cUrl = ConvertToURL( cFilename + ".swf" )
     
     oArgs = Array(_
                      MakePropertyValue( "URL", cURL ),_
                      MakePropertyValue( "FilterName", "impress_flash_Export" ),_
                      )
     
     oController = oDoc.getCurrentController()
     oFrame = oController.getFrame()
     
     oDispatcher = createUnoService( "com.sun.star.frame.DispatchHelper" )
     oDispatcher.executeDispatch( oFrame, ".uno:ExportTo", "", 0, oArgs() )
     'delete the sxi file
     kill cFilename + ".sxi"
End Sub


As far as invoking the macro, I do it with a batch file on windows. I'm not a Linux guy, so I don't know how the shell script would be written.

Assuming the macro is located at soffice>pptConv>ppt the windows bat file would look like this:

Code:

@ECHO OFF
"c:\openOfficeInstallDir\program\soffice" -invisible "macro:///pptConv.ppt.Main(%1,%2)"
ECHO 1


If you saved this batch file as c:\conversion\ppt.bat, you would run from the command line like so:
Code:

c:\conversion\ppt c:\path\to\my\ppt\file.ppt c:\path\to\my\dest\dir\


So you know, OO can export the ppt directly to a single .swf, but it adds odd actionscript makes the .swf's hard to navigate.

Also, the individual slides create by the macro process above will have the silde graphics, anda button that covers the whole stage. Sadly... nothing has instance names, so it can be a project picking out and killing the buttons. If you have a decompiler, you'll see what I mean. I tend to place a movie clip over the slides when I use them in another .swf to kill the hand cursor.

Only way around that is to use OO to convert the ppt to pdf, and then use pdf2swf to turn the pdf into an .swf. that takes care of the navigation slopiness, but I've found that pdf2swf makes a mess of the graphics. Play around with it and you'll see what I mean.

If you're unfamiliar with installing macros on OO, check out their support forum. It took me less than a day to findwhat I needed there when I was getting started with OO.

http://www.ooforum.org

You'll also find that OO will convert just about any office document... doc, xls, and rtf included to .swf.