OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Impress: Export slides into separate documents

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 4021
Location: Lawrence, Kansas, USA

PostPosted: Tue Apr 13, 2004 7:20 am    Post subject: Impress: Export slides into separate documents Reply with quote

This program does the following.
1A. Open Impress document
1B. Find out how many slides it has.
1C. Close it.

2A. Open Impress document.
2B. Delete ALL slides, EXCEPT for slide 1.
2C. Save the single slide document in the following formats....
* Impress
* PDF
* SWF (Flash)
* JPEG
2D. Close the single slide document WITHOUT SAVING. (Thus the original document on disk still has all of the original slides.)
2E. Repeat steps 2A thru 2D for slide 2, slide 3, etc.

So if you started with a slideshow named....

ScoPublicClaimsVsCourtFilings.sxi

You end up with a bunch of new files.....

ScoPublicClaimsVsCourtFilings -- page 1.sxi
ScoPublicClaimsVsCourtFilings -- page 1.pdf
ScoPublicClaimsVsCourtFilings -- page 1.sxf
ScoPublicClaimsVsCourtFilings -- page 1.jpeg
ScoPublicClaimsVsCourtFilings -- page 2.sxi
ScoPublicClaimsVsCourtFilings -- page 2.pdf
ScoPublicClaimsVsCourtFilings -- page 2.sxf
ScoPublicClaimsVsCourtFilings -- page 2.jpeg
ScoPublicClaimsVsCourtFilings -- page 3.sxi
ScoPublicClaimsVsCourtFilings -- page 3.pdf
ScoPublicClaimsVsCourtFilings -- page 3.sxf
ScoPublicClaimsVsCourtFilings -- page 3.jpeg
etc.
etc.


Code:

Sub Main
   ' 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 = "/home/danny/Desktop/SlideSplitter/SlideDocumentToSplit.sxi"
   cImpressDocToSplit = "C:\Documents and Settings\dbrewer\Desktop\SlideSplitter\SlideDocumentToSplit.sxi"

   SplitSlides( cImpressDocToSplit )
End Sub

Sub SplitSlides( cImpressDocToSplit )
   
   ' Open the document to find out how many pages it has.
   oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDocToSplit ), "_blank", 0, Array() )
   
   nNumPages = oDoc.getDrawPages().getCount()
   
   ' Now that we know how many pages it has, close it.
   oDoc.close( True )
   
   ' 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 = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDocToSplit ), "_blank", 0, Array() )
      
      ' 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 )

      ' Save the document as a new impress document.
      oDoc.storeToURL( ConvertToURL( cNewName + ".sxi" ), _
         Array() )

      ' Save it as a PDF.
      oDoc.storeToUrl( ConvertToURL( cNewName + ".pdf" ), _
         Array( MakePropertyValue( "FilterName", "impress_pdf_Export" ) ) )

      ' Save it as a Flash.
      oDoc.storeToUrl( ConvertToURL( cNewName + ".swf" ), _
         Array( MakePropertyValue( "FilterName", "impress_flash_Export" ) ) )

      ' Save it as a JPEG.
      oDoc.storeToUrl( ConvertToURL( cNewName + ".jpeg" ), _
         Array( MakePropertyValue( "FilterName", "impress_jpg_Export" ) ) )
      
      ' Close the document without saving it.
      oDoc.close( True )
   Next
   
End Sub



' 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
   oPropertyValue = createUnoStruct( "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


A much earlier version of this program is available at the useful
http://OOoMacros.org
web site. If you need useful macros, or want more programming examples of macros, I would encourage you to visit this site.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1609
Location: Wellington, New Zealand

PostPosted: Wed May 19, 2004 5:04 pm    Post subject: Reply with quote

but see also http://www.oooforum.org/forum/viewtopic.php?p=33699#33699
Export of JPG and SVG for example outputs the current page only.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Jun 30, 2004 5:54 am    Post subject: Reply with quote

This should really be a built in feature. When I clicked export to bmp, I expected alll of my slides to come with me.

PPT has a built in resolution ceiling that is rediculously low. For that reason we are switching to OOo - the ceiling is gone, but so is the ease of use. Bring the ease of use in, and I'll be converting more than ppts.
Back to top
freemant
General User
General User


Joined: 23 Feb 2005
Posts: 7

PostPosted: Sat Oct 11, 2008 11:17 pm    Post subject: Here is the solution Reply with quote

Below is the code that works:

Code:

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   oPropertyValue = createUnoStruct( "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 SplitPDFs
  dim oDoc as object
  oDoc = ThisComponent
  dim url as string
  url = oDoc.getURL()
  baseURL = Left( url, Len( url ) - 4 )
  nNumPages = oDoc.getDrawPages().getCount()
  For nPageToSave = 1 To nNumPages
    dim r as string
    r = Str(nPageToSave)+"-"+Str(nPageToSave)
    oDoc.storeToUrl( baseURL+nPageToSave+".pdf" ), Array( _
     MakePropertyValue( "FilterName", "impress_pdf_Export" ), _
     MakePropertyValue( "Overwrite", "True"),  _
     MakePropertyValue( "FilterData", Array( _
        MakePropertyValue( "PageRange", r ))))
  Next
End Sub
Back to top
View user's profile Send private message
msdexter
Newbie
Newbie


Joined: 24 Jul 2009
Posts: 1
Location: USA

PostPosted: Wed Oct 07, 2009 12:56 pm    Post subject: Reply with quote

it works fine !
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group